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

From: Date: Fri, 01 Aug 2003 20:38:43 +0000
Subject: #24910 [Opn]: in function scope, $GLOBALS is not superglobal
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-45193@lists.php.net to get a copy of this message
 ID:               24910
 Updated by:       cellog@php.net
 Reported By:      greg at chiaraquartet dot net
 Status:           Open
 Bug Type:         Arrays related
 Operating System: Windows XP
 PHP Version:      4.3.2
 New Comment:

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']));



Previous Comments:
------------------------------------------------------------------------

[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



Thread (7 messages)

« previous php.bugs (#45193) next »