Re: Re: Are exceptions allowed in php core?
| From: | Gustavo Lopes | Date: | Sun, 02 Sep 2012 08:24:34 +0000 |
| Subject: | Re: Re: Are exceptions allowed in php core? | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62658@lists.php.net to get a copy of this message | ||
On Sun, 02 Sep 2012 03:01:06 +0200, Stas Malyshev <smalyshev@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