On Thu, Aug 30, 2012 at 10:27 AM, Derick Rethans <der...@php.net> wrote: > On Wed, 29 Aug 2012, Stas Malyshev wrote: > >> >> Thanks, this is now fixed. It'll throw an exception now, saying >> >> that you can't traverse an already closed generator. >> > >> > Nothing in the core throws an exception, why would this?! >> >> I'd rather have it skip foreach, maybe producing a warning/notice. >> It'd otherwise also be only place generators throw exceptions, which >> is a bit unexpected. > > Indeed. Even though yield/generator is an iterator *internally*, > nothing on the language syntax side hints at that. Nothing even > indicates you're using "OO" there. > > This is unlike the SplIterators where are you are clearly constructing > fancy objects.
In their most trivial use (i.e. just sticking them into foreach) you won't notice that generator objects are actually, well, objects. But still you can work with them as objects and they also expose the Iterator API. E.g. you can call $gen->rewind() and this will throw an Exception (if it isn't rewindable at the moment). Do you disagree that this should throw an exception? Should it throw an error instead? If not, then why would the same rewind() call done internally in foreach not also throw an Exception? Why would that throw an error instead? It's two times the same thing, just invoked slightly different. Nikita -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php