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

2003-12-15 Thread Wouter van Vliet
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 ->
>  
> 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2003-12-15 Thread Robert Cummings
On Mon, 2003-12-15 at 04:23, Gerard Samuel wrote:
> 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?

It's global isn't it? SOunds like completeness.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] $GLOBALS containing itself!!!

2003-12-15 Thread Gerard Samuel
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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php