note 66706 rejected from language.variables.scope by bjori

From: Date: Sat, 27 May 2006 15:27:19 +0000
Subject: note 66706 rejected from language.variables.scope by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-112371@lists.php.net to get a copy of this message
Note Submitter: jas at rephunter dot net ---- I have run into a situtation using PHP 5.0.4 that has shown the using the global statement is not exactly equvalent to the use of the $GLOBALS superglobal. My code unsets and initializes a specific variable in some lower level functions, with the intent that it be a global variable, using the global statement. That is, in every function in which the variable appears, it is declared as global. Specifically, when tracing the program, I can see a global instance and a local instance with different values. This was causing a bug in my program. Of course this makes no sense. I think it that unsetting the variable in the lower level function could be the problem. Perhaps when the "global" version is unset, then initialed again, it is no longer global. So, either there is a bug in 5.0.4, or there is something that I am not doing correctly. In any case, the workaround is to replace each occurrence of the variable_name with $GLOBALS['variable_name'] and removing it from all global statements. Although I would have thought that using the superglobal should be equivalent to using the global statement as it seems to be documented, it is not, and now there is now only a single instance of the variable as intended, and the bug is fixed.

« previous php.notes (#112371) next »