Re: Re: Globals
| From: | Greg Beaver | Date: | Fri, 01 Aug 2003 21:43:43 +0000 |
| Subject: | Re: Re: Globals | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-158009@lists.php.net to get a copy of this message | ||
Jim,
My bad, I posted the wrong code. Try this instead to see the bug:
<?php function not_super()
{
var_dump(isset($GLOBALS['GLOBALS']));
return array_keys($GLOBALS);
}
//var_dump(not_super(), array_keys($GLOBALS));
not_super();
not_super();
?>
run this code, don't read it, you will see output of bool(false),
bool(false)
However, the following code works as expected!
<?php
function not_super()
{
return array_keys($GLOBALS);
}
var_dump(not_super(), array_keys($GLOBALS));
?>
GLOBALS will be present in both arrays.
Very odd behavior.
Note that in PHP 5.0.0b1, the first function does work, so this is fixed somewhere in there.
Greg
--
phpDocumentor
http://www.phpdoc.org
Jim Lucas wrote:
umm... That is what is going to happen when you follow your example. I think you are mistaken in what you are expecting... This line: $a = array_keys($GLOBALS); will give you an array of values that match the keys of the $GLOBALS array it won't copy the arrays. Try this. <PRE> <?php $a = array_keys($GLOBALS); foreach($a AS $key => $value) { echo $key."=>(".$value.")\n"; } ?> Jim Lucas ----- Original Message ----- From: "Greg Beaver" <greg@chiaraquartet.net> To: "Jim Lucas" <phplist@zonedzero.net> Cc: "Leif K-Brooks" <eurleif@buyer-brokerage.com>; <php-general@lists.php.net> Sent: Friday, August 01, 2003 1:42 PM Subject: Re: [PHP] Re: GlobalsHi Jim, The code you posted is correct, I never contested that. Read carefully. <?php function not_super() { var_dump(isset($GLOBALS['GLOBALS'])); $a = array_keys($GLOBALS); var_dump(isset($a['GLOBALS'])); } not_super(); ?> run this code, don't read it, you will see output of bool(false), bool(false) However, the following code works as expected! <?php function not_super() { return array_keys($GLOBALS); } var_dump(not_super(), array_keys($GLOBALS)); ?> GLOBALS will be present in both arrays. Very odd behavior. Greg Jim Lucas wrote:-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpactually, it does work and it does exist. Try using print_r() or print_r(array_keys($GLOBALS)); and you will see an entry for GLOBALS mine is located at #13 Jim Lucas ----- Original Message ----- From: "Greg Beaver" <greg@chiaraquartet.net> To: "Leif K-Brooks" <eurleif@buyer-brokerage.com> Cc: <php-general@lists.php.net> Sent: Friday, August 01, 2003 12:45 PM Subject: Re: [PHP] Re: GlobalsYes it does. I just ran the following, and I got "Greg is wrong." <?php $foo = 'Greg is wrong.'; echo $GLOBALS['GLOBALS']['GLOBALS']['GLOBALS']['foo']; ?>Try this code: <?php function blah() { var_dump($GLOBALS['GLOBALS']); } blah(); ?> It appears that in a function scope, it doesn't. This is definitely a bug, I'll post it if it hasn't already been noticed. Greg Leif K-Brooks wrote:Greg Beaver wrote:$GLOBALS does not contain a reference to itself