On Sun, 02 Sep 2012 03:01:06 +0200, Stas Malyshev <smalys...@sugarcrm.com> wrote:

For me, it behaves exactly like any other
iterator would behave if you had no more useful elements in it -
meaning, producing no elements. I do not understand why you think it
requires immediate break of the code flow and abandoning the execution
of the current function - after all, for the surrounding code the
situation where iterator has no elements is a normal situation for an
iterator, and iterating twice is indistinguishable - from the POV of the
surrounding code - from iterating an empty iterator once. Moreover, if
foreach() was supposed to have any side effects, none of these effects
would happen with empty return, so there's no danger here either. So I
believe the point that this condition requires immediate exit from the
code flow needs some explanation.

Precisely. The fact that everything happens normally except for the iterator giving out an empty set is what makes this an insidious problem. The request will be fully processed, but you will have a bug that may manifest itself in a relatively safe manners (e.g. a search page giving no results) -- though that could possibly cost a business money -- or in far more destructive manners (for instance, if the iterator was to return a set of files or database entities to keep when deleting others).

--
Gustavo Lopes

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

Reply via email to