Skip to content
Advertisement

Tag: scope

How to Use an Outside Variable Inside a For Loop (Scope)

Simple question that I haven’t seen answered anywhere: How can I use an outside $variable, inside a for loop? In my PHP code, I have a SplDoubleyLinkedList full of friends names, and I am looping through them one by one to use in an if statement that compares the current friend to the $friend name parameter. How can I change

Cant access variable outside of function in wordpress

I am having trouble understanding why I can’t access the $theme_text_domain when it is placed outside of the following function in wordpress. I am getting the following error but if I place it inside the function it works fine. But I would really like to just state the text domain once for all of the functions inside of the functions.php

Fatal Undefined Function Error with included files in PHP

Here is the statement from PHP manual: When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward. However, all functions and classes defined in the included file have

PHP variable scope within Try/Catch block

In PHP, how do variable scope rules apply to Try/Catch blocks? Do variables declared within the try block go out of scope when the block has finished? Or are they in scope until the end of the function/method? For example: Is this valid? Or should $o = NULL; be set before the try/catch to keep $o in scope? (I know

understanding why echo doesnt work within a php class function

I’m trying to debug a class and using print_r and echo to view the variables as the script progresses. However for some reason I can’t seem to get any output from within the function, i’ve declared the function public but can’t get any output using print, echo or print_r. I’m misunderstanding something fundamental here – can anyone help please. here’s

Is it possible to access outer local variable in PHP?

Is it possible to access outer local varialbe in a PHP sub-function? In below code, I want to access variable $l in inner function bar. Declaring $l as global $l in bar doesn’t work. Answer You could probably use a Closure, to do just that… Edit : took some time to remember the syntax, but here’s what it would look

Advertisement