Re: Re: Generators in PHP
| From: | Nikita Popov | Date: | Sun, 22 Jul 2012 15:52:46 +0000 |
| Subject: | Re: Re: Generators in PHP | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-61628@lists.php.net to get a copy of this message | ||
On Sat, Jul 21, 2012 at 6:31 PM, Jared Williams
<jared.williams1@ntlworld.com> wrote:
> Can't yield a reference to an array item directly.
>
> Eg.
>
> function &map(array &$row)
> {
> yield $row[0];
> }
Thanks, this is fixed now.
> Also seems to be a problem with iterating
>
> foreach(map($row) as &$value)
>
> cannot be done without a fatal error
>
> $i = map($row);
> foreach($i as &$value)
>
> however works.
This was an old foreach restriction that never really made sense and
makes even less sense once generators are in. So I dropped it. Now
everything can be iterated by-reference.
> Seems relatively easy to trigger a infinite loop atm.
>
> Typo'd a SQL table name which caused an exception within PDO inside a
> generator function, which then caused an infinite loop.
I forgot to rethrow the exception in the foreach scope. Should be fixed now.
Thanks for your feedback!
Nikita