On Tue, Aug 14, 2012 at 7:59 PM, Aaron Holmes <aa...@aaronholmes.net> wrote:
> Thanks for clarifying. It makes sense now, considering foreach's behavior
> and the generators statefulness allowing what otherwise seems inconsistent.
> However, might it make sense to no-op instead of erroring? If generators
> allow rewind(), it would be unexpected to receive an error for calling it.

A no-op is the current behavior. The issue with that is that you could
accidentally reuse an already depleted (or partially depleted)
generator. I.e. you run it through one loop and then through another
one. With a no-op rewind it would be hard to figure out what the issue
is. The error makes clear that you tried to iterate an already
iterated generator.

Furthermore, if you indeed *want* to partially traverse a generator in
several loops, you can simply wrap it in a NoRewindIterator. This has
the additional benefit of making it more clear what you want to do.

Nikita

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

Reply via email to