Re: [VOTE] Generators
| From: | Derick Rethans | Date: | Wed, 29 Aug 2012 21:19:44 +0000 |
| Subject: | Re: [VOTE] Generators | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62587@lists.php.net to get a copy of this message | ||
On Wed, 29 Aug 2012, Nikita Popov wrote:
> On Wed, Aug 29, 2012 at 10:10 PM, Derick Rethans <derick@php.net> wrote:
> > On Wed, 29 Aug 2012, Nikita Popov wrote:
> >
> >> > function &bind(array $keys, array &$row)
> >> > {
> >> > foreach($keys as $key)
> >> > yield $key => $row[$key];
> >> > }
> >> >
> >> > $row = [];
> >> > $it = bind(['a', 'b'], $row);
> >> >
> >> > foreach($it as $key => &$ref)
> >> > echo $key;
> >> > echo "\n";
> >> > foreach($it as $key => &$ref)
> >> > echo $key;
> >>
> >> Thanks, this is now fixed. It'll throw an exception now, saying that
> >> you can't traverse an already closed generator.
> >
> > Nothing in the core throws an exception, why would this?!
>
> To my knowledge all iterator-related functionality is supposed to
> throw exceptions (as it is a feature related to the object oriented
> part of PHP). At leas this is what a quick search of the code base
> gave me. (See
> http://lxr.php.net/xref/PHP_TRUNK/ext/spl/spl_dllist.c#1248
> for example).
"ext/spl" - SPL is not *core* language. The generators are. Don't throw
exceptions from core features!
Derick