rfc:generators
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
rfc:generators [2012/09/01 17:22] – Change state to "Implemented" nikic | rfc:generators [2012/12/23 23:44] – Add ::throw() method nikic | ||
---|---|---|---|
Line 189: | Line 189: | ||
| | ||
mixed send(mixed $value); | mixed send(mixed $value); | ||
+ | mixed throw(Exception $exception); | ||
} | } | ||
</ | </ | ||
Line 228: | Line 229: | ||
* '' | * '' | ||
* '' | * '' | ||
+ | * '' | ||
==== Yield syntax ==== | ==== Yield syntax ==== | ||
Line 392: | Line 394: | ||
$logger-> | $logger-> | ||
$logger-> | $logger-> | ||
+ | </ | ||
+ | |||
+ | ==== Throwing into the generator ==== | ||
+ | |||
+ | Exceptions can be thrown into the generator using the '' | ||
+ | context and then resume the generator. It is roughly equivalent to replacing the current '' | ||
+ | resuming then. If the generator is already closed the exception will be thrown in the callers context instead (which is equivalent to replacing | ||
+ | the '' | ||
+ | other exception is thrown). | ||
+ | |||
+ | An example of the functionality: | ||
+ | |||
+ | <code php> | ||
+ | function gen() { | ||
+ | echo " | ||
+ | try { | ||
+ | yield; | ||
+ | } catch (Exception $e) { | ||
+ | echo " | ||
+ | } | ||
+ | echo " | ||
+ | } | ||
+ | |||
+ | $gen = gen(); | ||
+ | $gen-> | ||
+ | $gen-> | ||
+ | // and " | ||
</ | </ | ||
rfc/generators.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1