On Tue, 5 Jun 2012 19:35:14 +0200, Nikita Popov wrote:
Before going any further I'd like to get some comments about what you
think of adding generator support to PHP.
I approve.
A few comments on the current RFC:
* The RFC is too vague.
* You're violating the contract of Iterator left and right. current()
and key() should return false when !valid(). next() is underspecified.
valid() refers to a section that doesn't exist. And if you cannot
implement rewind(), doing nothing is not an option. In fact, if you
can't implement Iterator in full, you should implement Traversable
instead. RewindableGenerator could perhaps implement Iterator though --
but I find the nature of RewindableGenerator very strange. Whether an
iterator is rewindable or not seems to be related to the nature of the
generator (e.g., is it reading packets from the network). It's not
something you can wrap a non-rewindable generator and expect it to work.
So it's a sort of unsafe operation, like a cast in C.
* Overall, the RFC is very underspecified. We never have a formal
description of what a generator is and exact semantics of it. There is
no reference to exceptions. What to do if the generator returns
function. If the generator can be a function method.
* There are missing sections
I suppose this is a work in progress and that you just want to gauge
the general interest, and I hope you take these considerations into
account.
--
Gustavo Lopes
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php