RE: Wierd Variable Initialization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 25 September 2008 03:45, VamVan advised:

> So guys,
> 
> I found some thing strange that happened to me yesterday. Its small
but
> kinda freaked me out.
> 
> So I have a tokenmap.php that I include include in different
configuration
> files. Some are classes and some are simple php files.
> 
> So in my tokenmap.php I have declared an array as global.
> 
> SO $GLOBAL['tokenmap'] = array()
> 
> As a good programming practice what I did was:
> 
> require_once('tokenmap.php');
> $tokenmap = array();
> $tokenmap = $GLOBAL['tokenmap'];
> print_r($tokenmap);
> 
> The above displays empty array
> 
> But when I do this , it works
> 
> require_once('tokenmap.php');
> $tokenmap = $GLOBAL['tokenmap'];
> print_r($tokenmap);
> 
> Its kind of wierd for me. I am trying to understand. Can some one shed
> some light on it for me.

Well, $GLOBALS['tokenmap'] is *exactly* *the* *same* *thing* as
$tokenmap when you're in the global scope (which I assume you are for
what you describe here to make sense).  So the assignment:

   $tokenmap = array();

is the same as:

   $GLOBALS['tokenmap'] = array();

And the assignment:

   $tokenmap = $GLOBALS['tokenmap'];

is essentially useless as it's the same as:

   $tokenmap = $tokenmap;

... or:

   $GLOBALS['tokenmap'] = $tokenmap;

... or even:

   $GLOBALS['tokenmap'] = $GLOBALS['tokenmap'];

Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: m.ford@xxxxxxxxxxxxxx
Tel: +44 113 812 4730




To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux