Re: Re: Reference handling change and PHP 4.4.0

From: Date: Fri, 16 Sep 2005 12:21:16 +0000
Subject: Re: Re: Reference handling change and PHP 4.4.0
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-19046@lists.php.net to get a copy of this message
On Thu, 15 Sep 2005, Todd Ruth wrote: > Aha! That was the inspiration I needed to get the right > combination of "&"s. The following bit of code behaves > differently under 4.3 vs 4.4: > > <?php > function f(&$a) { return $a; } > $x = array('a','b','c'); > foreach (array_keys($x) as $k) { > // I think the following line disconnects $y in 4.3 > // but leaves $y connected in 4.4 > $y =& f($x[$k]); > $z[] =& $y; > } > var_dump($x); > var_dump($z); > ?> > > My guess would be that in 4.3 the engine tries to do the > reference even though it may be dangerous. That would > "disconnect" $y from the previous $z[]. 4.4 knows the > reference is impossible and leaves $y connected to the > previous $z[]. Is that analysis correct, engine gurus? Yes, it is. This has bitten me too a couple of times. But ofcourse, the new behavior *is* the correct one. Derick -- Derick Rethans http://derickrethans.nl | http://ez.no | http://xdebug.org

« previous php.internals (#19046) next »