I know this is kind of a hacky thing I’m trying here, but I’m wondering if this is even possible. is there anyway I can access the $x variable in the following code, without passing arguments?
function foo() {
$x = 1;
return bar();
}
function bar() {
//get $x from foo here somehow?
return $x ? 'stuff' : 'other stuff';
}
I am not sure why, but you can use globals that opens up to a whole thing, but i will show you:
Here is the demo: http://codepad.org/fPqUXzyC
It is always better to not use globals and just pass parameters, but if you cannot you could use globals