Wasn't part of the "negotiation" when 4.4 was created that the behavior would be the same as 4.3 (excluding anything that happened because of a memory corruption)? (I'm not counting the notices as behavior.)
I don't see how it can be argued that "$y =& ..." leaving $y connected to it's old buddies can be considered correct. I see why $y should not be tied to the rvalue if the rvalue is not suitable for being used as a reference, but that doesn't change the fact that this code clearly indicates $y should be detached from anything it was formerly attached to. Wouldn't the php philosophy indicate $y should be unset before being assigned by value in this case? (and after all, doing that preserves BC!) Please elaborate on the idea that the new behavior is correct. BTW, when you say "This has bitten me too a couple of times", are you saying that you were aware of a BC break beyond memory corruption and didn't mention it? Thanks, Todd On Fri, 2005-09-16 at 08:21 -0400, Derick Rethans wrote: > 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 > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php