note 66706 added to language.variables.scope

From: Date: Fri, 26 May 2006 14:36:57 +0000
Subject: note 66706 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-112335@lists.php.net to get a copy of this message
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. ---- Server IP: 216.194.113.175 Probable Submitter: 69.23.252.228 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.variables.scope.php Edit -- http://master.php.net/note/edit/66706 Del: integrated -- http://master.php.net/note/delete/66706/integrated Del: useless -- http://master.php.net/note/delete/66706/useless Del: bad code -- http://master.php.net/note/delete/66706/bad+code Del: spam -- http://master.php.net/note/delete/66706/spam Del: non-english -- http://master.php.net/note/delete/66706/non-english Del: in docs -- http://master.php.net/note/delete/66706/in+docs Del: other reasons-- http://master.php.net/note/delete/66706 Reject -- http://master.php.net/note/reject/66706 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#112335) next »