|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-08-01 14:47 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 06:00:01 2025 UTC |
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']));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