Re: Generators in PHP
| From: | Stas Malyshev | Date: | Thu, 26 Jul 2012 00:20:48 +0000 |
| Subject: | Re: Generators in PHP | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-61800@lists.php.net to get a copy of this message | ||
Hi!
> The implementation is outlined in the RFC-stub here:
> https://wiki.php.net/rfc/generators
>
> Before going any further I'd like to get some comments about what you
> think of adding generator support to PHP.
Some notes on the RFC:
1. I think we should support rewind() by just creating a new generator
instance (i.e. doing the same that is done when generator is called for
the first time). If it depends on the resource that generator changes as
a side effect, so be it. rewindable() looks like unnecessary
complication which IMHO will not be useful in most cases.
2. I understand the pre-yield code is called on current(). What about
key()? I think it makes sense to call it there too - i.e. pre-yield code
is called whenever first key() or current() - it should be made explicit.
3. return values. I think non-empty return in generator should produce a
notice or E_STRICT.
4. What happens to the state variables when generator is cloned? Just
addref or real cloning for objects?
5. Are multiple yields allowed? I.e. the rfc mentions something like
yield yield $a - what that would mean? I'd allow yield only be applied
to variable expression (lval) because double yield doesn't make sense to
me, but maybe I miss something.
6. “Sending values” section seems to be missing. Especially useful would
be to cover what happens with keys there and what is the syntax there -
is it just "$a = yield;"? Or does it mean when yield is used in
expression it becomes incoming yield? And, last but not least - do we
need sending into generators at all?
6. What happens if you send into a by-ref generator? Is the data sent
by-ref then? What if it's an expression that can't be send by-ref?
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227