Re: 4.3.11/5.0.4 (Was: changed behavior: property of a string)
| From: | Andi Gutmans | Date: | Thu, 23 Dec 2004 22:48:39 +0000 |
| Subject: | Re: 4.3.11/5.0.4 (Was: changed behavior: property of a string) | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-14196@lists.php.net to get a copy of this message | ||
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