#24910 [Opn->Bgs]: in function scope, $GLOBALS is not superglobal

From: Date: Fri, 01 Aug 2003 20:49:17 +0000
Subject: #24910 [Opn->Bgs]: in function scope, $GLOBALS is not superglobal
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-45195@lists.php.net to get a copy of this message
ID: 24910 Updated by: iliaa@php.net Reported By: greg at chiaraquartet dot net -Status: Open +Status: Bogus Bug Type: Arrays related Operating System: Windows XP PHP Version: 4.3.2 New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php First of all accessing $GLOBALS as $GLOBALS['GLOBALS'] is just plain wrong, you should just use $GLOBALS. If you look @ var_dump($GLOBALS) you'll see ["GLOBALS"] is infact a reference to itself, &array(). You could do something like $GLOBALS['GLOBALS']['GLOBALS']['GLOBALS']['_ENV'] and it would work because each globals array contains a reference to itself. This reference is only avaliable inside the global (main()) scope, which is why you cannot access it from inside the function. Previous Comments: ------------------------------------------------------------------------ [2003-08-01 15:38:43] cellog@php.net an interesting thing: the following code does work as expected. Perhaps the index is not set unless $GLOBALS is accessed globally? function not_super() { // var_dump($GLOBALS['GLOBALS']); var_dump(isset($GLOBALS['GLOBALS'])); $a = array_keys($GLOBALS); var_dump(isset($a['GLOBALS'])); } not_super(); // var_dump(isset($GLOBALS['GLOBALS'])); $a = array_keys($GLOBALS); // var_dump(isset($a['GLOBALS'])); ------------------------------------------------------------------------ [2003-08-01 15:32:34] cellog@php.net This is not bogus. Did you try the code? The whole point is that in a function, $GLOBALS['GLOBALS'] !== $GLOBALS. It should be the same. In global scope, $GLOBALS['GLOBALS'] === $GLOBALS Greg ------------------------------------------------------------------------ [2003-08-01 15:23:54] iliaa@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php $GLOBALS['GLOBALS'] is actually a reference to $GLOBALS if you want to access the globals just use $GLOBALS. ------------------------------------------------------------------------ [2003-08-01 14:47:52] greg at chiaraquartet dot net Description: ------------ the $GLOBALS variables contains indexes to every superglobal except 'GLOBALS' in function scope. In global scope, it contains the 'GLOBALS' index as a self-reference Reproduce code: --------------- <?php function blah() { var_dump($GLOBALS['GLOBALS']); } blah(); ?> Expected result: ---------------- var_dump() of the $GLOBALS superglobal Actual result: -------------- Notice: Undefined index: GLOBALS in c:\web pages\chiara\a1.php on line 3 NULL ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=24910&edit=1

« previous php.bugs (#45195) next »