global keyword and references

From: Date: Thu, 02 Aug 2001 14:55:52 +0000
Subject: global keyword and references
Groups: php.general 
Request: Send a blank email to php-general+get-60916@lists.php.net to get a copy of this message
Hi, I'm having a problem using the global keyword and references. To the best of my logic and PHP's documentation, the following code: <? $a = 1; $b = 2; function Sum() { global $a, $b; $b = &$a; // <- $b is for now 1 } Sum(); echo "a=$a b=$b"; ?> should output "a=1 b=1" since in the Sum() function I set $b to point to $a, and both of them refer to global variables $a and $b. Moreover, inside Sum() $b is 1 after the assignment. Getting out of the function, $b returns to the old value. If I use $GLOBALS["b"] = &$GLOBALS["a"]; echo "a=$a b=$b"; will output "a=1 b=1" as expected. Please clear me out on this one, philip

« previous php.general (#60916) next »