Richard K Miller wrote:
>> It is one of these things that make perfect sense when you think about
>> it a little bit.  Yes, it catches some people, just like strpos()
>> returning character position 0 on a first-char match catches some
>> people.  There is no way to fix things like these without completely
>> breaking things.  If we had strpos not use 0-based string positions or
>> if we arbitrarily broke references after loops, all sorts of other
>> things would start breaking and no longer make sense.
>>
>> -Rasmus
> 
> Rasmus,
> 
> Thanks for your reply. With respect, this seems to be in a different
> class from matching strings with character position 0, IMO.
> 
> What about unsetting the iterator before foreach() looping begins? The
> iterator is altered anyway, so would this prevent it from being
> "attached" to previous foreach() iterations?

It would be arbitrarily breaking an explicit reference.  I know I have
code lying around that relies on multiple loops cleaning up a big
complicated multi-level array.  I do ugly things with references into
that array and it would completely break if PHP magically deleted my
references whether they are in the iterator or elsewhere.

This has been this way for 6+ years and it is well documented on the
http://php.net/foreach page.  (see the big red warning box)

-Rasmus

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

Reply via email to