note 53316 deleted from language.variables.scope by sean
| From: | sean@php.net | Date: | Fri, 17 Jun 2005 00:29:37 +0000 |
| Subject: | note 53316 deleted from language.variables.scope by sean | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-90560@lists.php.net to get a copy of this message | ||
Note Submitter: Andy Morris
----
To answer "dpk at dpk dot net", here is the reason as I see it.
I've added some extra debug lines to show what's happening...
<?php
print "<pre>";
$GLOBALS['foo'] = array ('bar' => 'frank'); // global variable
foo is now an array
print $GLOBALS['foo']['bar'] . "\n"; // OK, prints
"frank" because foo is an array
var_dump($GLOBALS['foo']); // shows foo array definition and contents
$foo = $GLOBALS['foo']['bar']; // OK, but sets global variable foo to string
"frank"
var_dump($foo); // confirms foo is now just a string, NOT an array
print $GLOBALS['foo']['bar']; // WRONG! global 'foo' is no longer an
array
print "</pre>";
?>
This now prints:
frank
array(1) {
["bar"]=>
string(5) "frank"
}
string(5) "frank"
f
The final print out of $GLOBALS['foo']['bar'] produces the single "f",
and to be honest I don't know what I'd expect it to print here as it is now undefined at
this point.
So frankly ;-), this is not in fact contrary to what you might expect.