Re: strange reference behavior
| From: | Martin Ellingham | Date: | Sat, 01 Sep 2007 10:39:12 +0000 |
| Subject: | Re: strange reference behavior | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-261586@lists.php.net to get a copy of this message | ||
Robert Enyedi wrote:
Hi, I've been studying the PHP reference mechanism (with PHP 5.2.1) and I'm unsure if the following behavior is normal. This code works as expected:That's my understanding of it. Martin$a = 2; $b = &$a; //$c = &$a; $c = $b; $a = 1;echo $c."\n"; // Prints "2" as expectedbut this one does not:$a = 2; $b = &$a; $c = &$a; $c = $b; // Should overwrite the previous assignment, so $c // should get a copy of $b (and NOT a reference) $a = 1; echo $c."\n"; // I would expect "2", but prints "1"Could anyone please clarify why this happens? Regards, Robert This is because PHP5 has changed the default behaviour and $a = $b is now call by reference as standard.