ID: 24910 Updated by: [EMAIL PROTECTED] Reported By: greg at chiaraquartet dot net Status: Bogus Bug Type: Arrays related Operating System: Windows XP PHP Version: 4.3.2 New Comment:
[EMAIL PROTECTED]: every example you have there are not stupid, they're EXTREMELY stupid. why would you make $GLOBALS global?! Anybody doing that alone should be spanked at least.. :) That said, there is NO bug here, move along.. Previous Comments: ------------------------------------------------------------------------ [2003-08-01 15:56:33] [EMAIL PROTECTED] The reason this is a bug is this code deletes the $GLOBALS array, and someone might do it by accident: <?php function stupid() { global $GLOBALS; var_dump($GLOBALS); // outputs NULL } stupid(); ?> Someone just posted to php.general asking about this exact issue, which is why I posted the bug. Last I checked, the definition of a bug is unexpected behavior, and this qualifies. It's rare, but perhaps there is something more critical hidden in the fact that this doesn't work? Since you're insistent, I'll leave this as bogus, but I strongly encourage you to reconsider Note that this code works as expected: <?php function worksforsomereason() { global $GLOBALS; var_dump($GLOBALS); } worksforsomereason(); $GLOBALS; ?> Once $GLOBALS has been overwritten, it is irretrievable within function scope. At the very least, a warning or notice should be thrown. This is a bug. If it is not to be fixed, the documentation might use a warning for dummies. Greg ------------------------------------------------------------------------ [2003-08-01 15:49:16] [EMAIL PROTECTED] 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. ------------------------------------------------------------------------ [2003-08-01 15:38:43] [EMAIL PROTECTED] 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] [EMAIL PROTECTED] 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] [EMAIL PROTECTED] 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. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/24910 -- Edit this bug report at http://bugs.php.net/?id=24910&edit=1