Re: Globals
| From: | Greg Beaver | Date: | Fri, 01 Aug 2003 19:21:17 +0000 |
| Subject: | Re: Globals | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-157993@lists.php.net to get a copy of this message | ||
Hi Chris,
Chris Boget wrote:
function blah() { //global $GLOBALS; echo 'Globals: <pre>'; print_r( $GLOBALS ); echo '</pre>'; } As it is shown above, with the 'global $GLOBALS' line commented out, the print_r() works and shows all the currently defined variables and their corresponding values. However, if I declare $GLOBALS as global, nothing gets printed out. Why?the global $GLOBALS directive is the equivalent of this PHP code: $GLOBALS = &$GLOBALS['GLOBALS']; $GLOBALS does not contain a reference to itself, so you are essentially setting $GLOBALS to refer to nothing! I'm not sure it is a great idea ot allow this, perhaps the internals folks can answer on that one.
Wouldn't the 'global $GLOBALS' line be more or less redundant in most cases? Because $GLOBALS is a superglobal (though, it isn't really)? Why would it affect whether or not $GLOBALS actually hasIt appears that $GLOBALS is not a superglobal because a superglobal always has an index in the $GLOBALS array.
While I'm on this subject, why isn't $GLOBALS always a superglobal? For example, this doesn't work: function innerFunc() { echo $GLOBALS['blah']; } function outerFunc() { innerFunc(); } $blah = 'bob'; outerFunc(); Nothing gets echoed from innerFunc(). Why? If anyone can offer any insight as to what is going on, I'd be ever so appreciative.This code worked for me, I saw "bob." Did you post the example you meant to? Greg -- phpDocumentor http://www.phpdoc.org