RE: [PHP] $GLOBALS containing itself!!!

From: Date: Mon, 15 Dec 2003 09:56:02 +0000
Subject: RE: [PHP] $GLOBALS containing itself!!!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-172725@lists.php.net to get a copy of this message
On maandag 15 december 2003 10:24 Gerard Samuel told the butterflies: > Just curious about something I came across. > I was looking at the $GLOBAL array, to see what my script was leaving > behind. $GLOBALS contains a reference to itself. > Even though its a reference, whats the sense with that?? > Once its global, why should it have to call on itself? > Im currently running php 4.3.4 on FreeBSD 4.9 > > Thanks > > A script to try out -> > <?php > > header('content-type: text/plain'); > > var_dump(isset($GLOBALS['GLOBALS']['GLOBALS'])); // returns true > > // Prints out the $GLOBALS array > // including one reference to itself > // then starts another but quits with *RECURSION* var_dump($GLOBALS); > > > Well .. it basically just "Contains a reference to every variable which is currently available within the global scope of the script. The keys of this array are the names of the global variables.". Since $GLOBALS itself is global, that too is contained. So: var_dump(isset($GLOBALS['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS ']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBAL S']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBA LS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOB ALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLO BALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GL OBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['G LOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS'][' GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS'][ 'GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS'] ['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS' ]['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS ']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBAL S']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBA LS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOB ALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLO BALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GL OBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['G LOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS'][' GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS'][ 'GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS'] ['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS' ]['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS ']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBAL S']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBA LS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOB ALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLO BALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GL OBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['G LOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS'][' GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS'][ 'GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS'] ['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS' ])); Will still print out true. the displaying of *RECURSION* is to prevent, well .. ehmm, recursively printing out the $GLOBALS array over and over again. This is something new in PHP 4.0.4. Read the manual on page http://nl3.php.net/manual/en/function.print-r.php: Note: Prior to PHP 4.0.4, print_r() will continue forever if given an array or object that contains a direct or indirect reference to itself. An example is print_r($GLOBALS) because $GLOBALS is itself a global variable that contains a reference to itself. :), Wouter

« previous php.general (#172725) next »