> -----Original Message-----
> From: Nikita Popov [mailto:nikita....@gmail.com] 
> Sent: 22 July 2012 16:53
> To: Jared Williams
> Cc: Nikita Popov; PHP internals
> Subject: Re: [PHP-DEV] Re: Generators in PHP
> 
> On Sat, Jul 21, 2012 at 6:31 PM, Jared Williams 
> <jared.willia...@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!

No problem. 

Though here is seemingly another problem, though it could be within
spl's MultipleIterator()

function a()
{
        yield 'a';
        yield 'aa';
}

function b()
{
        yield 'b';
        yield 'bb';
}

$m = new MultipleIterator();
$m->attachIterator(a());
$m->attachIterator(b());
foreach($m as $v)
{
        list($a, $b) = $v;
        var_dump($a, $b);
}

causes a seg fault, whereas the vanilla array version

$m = new MultipleIterator();
$m->attachIterator(new ArrayIterator(['a', 'aa']));
$m->attachIterator(new ArrayIterator(['b', 'bb']));
foreach($m as $v)
{
        list($a, $b) = $v;
        var_dump($a, $b);
}

works fine. 

Jared



-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to