At 11:50 PM 12/22/2004 +0100, Edin Kadribasic wrote:
Andi could you have a look at  #31118 marked critical "Two consecutive
foreach loops produce different results".

Hi Edin,

I looked into this problem. It's actually not a bug but just "weird" behavior as a result of PHP blocks not having scope.
Basically the first foreach() statement leaves the value variable ($v) as a reference. When the second loop runs, it "assigns" the current array's position to $v. Because $v was a reference it'll actually overwrite the previously pointed to value.


Now we can't go and unset($v) at the end of the foreach() statement as I bet there are many applications out there that take advantage of the last value staying in the $v variable after the foreach() finishes.

The only thing I have in mind is possible emitting an E_STRICT during the foreach() loop if the loop value variable is a reference. However, just from looking at make test this might potentially break many scripts which are using E_STRICT and/or confuse their authors. Not sure how to weight that, and as we haven't had many complaints about this behavior I'm not sure it's worth it.

Andi

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to