The scope of a variable within a function is local to the function unless the variable name is taken from the global space. If you want the variable to be in the global space:
Code:
func1(){
# make var global
global $theVariable;
$theVariable = "whatever";
func2();
}
# similarly
func2(){
# globalize
global $theVar;
echo $theVar;
}
In ingresman's post there is passing of values not the identical variable. You could achieve basically the same thing by passing the variable by reference.
In both cases I described the variable exists in the global scope. If you don't want that you still could pass it to the second function per reference:
class my_var {
var $theVariable;
function set($value){
$this->theVariable=$value;
}
function to_string(){
echo $this->theVariable;
}
}
$TheVar=New my_var;
$TheVar->set("mick43");
$theVar->to_string();
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.