Bug #70965 [Opn]: `yield from` with a common iterator primes too much
Edit report at https://bugs.php.net/bug.php?id=70965&edit=1
ID: 70965
Updated by: requinix@php.net
Reported by: srice at fb dot com
Summary: yield from with a common iterator primes too much
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: Linux
PHP Version: 7.0.0RC7
Block user comment: N
Private report: N
New Comment:
Looks similar to bug #70904.
Previous Comments:
------------------------------------------------------------------------
[2015-11-24 17:35:25] srice at fb dot com
Description:
------------
When two separate generator instances yield from a common iterator the second element
of the iterator gets skipped. There is a test case to keep this from happening with a common shared
generator (and the fix keeps track of which generator is priming or not) but it doesnt work with
iterators. See the sample script below (which is mostly just a small change to the
multiple_yield_from_on_same_generator test that already exists).
Test script:
---------------
<?php
function it() {
yield from [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
}
function bar($g) {
yield from $g;
}
$gen = it();
$gens[] = bar($gen);
$gens[] = bar($gen);
do {
foreach($gens as $g) {
var_dump($g->current());
$gen->next();
}
} while ($gen->valid());
Expected result:
----------------
int(1)
int(2)
int(3)
int(4)
int(5)
int(6)
int(7)
int(8)
int(9)
int(10)
Actual result:
--------------
int(1)
int(3)
int(4)
int(5)
int(6)
int(7)
int(8)
int(9)
int(10)
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70965&edit=1
Thread (7 messages)