Hi!

> More importantly, there is no other satisfactory solution (except a fatal  
> error). foreach has no return value, so it has no other way to signal a  
> failure. If we used a notice or a warning here what would happen is that  
> code that used generators with an invalid state would, except for the  
> notice, work as if it had been given an empty iterator. Put another way,  
> it would fail with only a notice, and continue. That is a far more serious  
> problem. In other circumstances where we emit warnings, we usually have a  
> return value the caller can check for error conditions.

I'm not sure I understand why you think behaving as it is an empty
iterator and producing an error message is "far more serious problem".
Could you explain that? 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.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

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

Reply via email to