Page 2 of 2
Posted: Mon Aug 21, 2006 11:07 am
by bindermichi
feyd wrote:"global $foo" is identical to $GLOBALS['foo'], they're interchangable.
Code: Select all
[feyd@home]>php -r "$foo = true; function foo(){global $foo; $foo = 1234; $GLOBALS['foo'] = 'asdf'; var_dump($foo);} foo(); var_dump($foo);"
string(4) "asdf"
string(4) "asdf"
Ok, didn't read that way
...but to prevent your example I used the static, which didn't work out right...
Posted: Mon Aug 21, 2006 11:15 am
by feyd
"static" doesn't do anything in the global scope; it's global, there's nowhere for it to go.
Posted: Mon Aug 21, 2006 12:25 pm
by sweatje
bindermichi wrote:Hmm... as far as i read the manual, there's a difference between "$GLOBALS[''];" and "global $var;"
By declaring $a and $b global within the function, all references to either variable will refer to the global version.
Notice how $GLOBALS exists in any scope, this is because $GLOBALS is a superglobal.
...and if I learned one thing in programming class... it's never to use superglobals, unless you have to

I believe you are confusing two ways of accessing a global variable (though the global keyword and through the $GLOBALS superglobal) with the concept that globals are bad. This is the case (that you should try to avoid the use of global variables) but you ARE still using them with either method of access. Changing how you access a global varaible does not reduce your dependancy on it.
In my own code I entirely avoid the global keyword. I would much rather grab a global from the big, ugly $GLOBALS['some_var'] as a constant reminder to me that I should be execising caution when doing so.
Posted: Mon Aug 21, 2006 1:17 pm
by bindermichi
sweatje wrote:
I believe you are confusing two ways of accessing a global variable (though the global keyword and through the $GLOBALS superglobal) with the concept that globals are bad. This is the case (that you should try to avoid the use of global variables) but you ARE still using them with either method of access. Changing how you access a global varaible does not reduce your dependancy on it.
In my own code I entirely avoid the global keyword. I would much rather grab a global from the big, ugly $GLOBALS['some_var'] as a constant reminder to me that I should be execising caution when doing so.
K, ... guess it's monday after all
Well, it works with the global array, so I guess for debugging the functions this will do.