Re: Generators in PHP

From: Date: Fri, 08 Jun 2012 11:24:49 +0000
Subject: Re: Generators in PHP
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-60781@lists.php.net to get a copy of this message
On Thu, Jun 7, 2012 at 10:46 AM, Gustavo Lopes <glopes@nebm.ist.utl.pt> wrote: > I mean how do you deal with "return $foo" in the body of the generator? Does > it work like a final yield? Is the return value ignored? Currently there will be a fatal error if return statements (with values) are used in the generator. In the future I'd like to use the return value as the result of a yield from / yield* expression, as it is currently done in Python and JavaScript. This is particularly useful if you are delegating control to another coroutine. This way you can for example break down a coroutine-based parser into several functions (instead of having one big ugly function). > Are you planning on any internal API for functions to implement generators > (though I really haven't thought how that would work)? I don't think that this is possible. Generators require that the execution context is suspended in some way and we have to that control only over userland code, not internal C code. Nikita

« previous php.internals (#60781) next »