<?php
function gen($a = 0) {
yield 1;
yield 2;
yield 3;
yield 4;
yield 5;
}
function bar($gen) {
yield from $gen;
}
$gen = gen();
$gens[] = bar($gen);
$gens[] = bar($gen);
do {
foreach ($gens as $g) {
echo "Current: ";
var_dump($g->current());
// Notice - We are advancing the underlying gen, not either of the things
// gens in the array. If we delegate properly, then our other generators
// should be implicitly advancing as well.
$gen->next();
}
} while($gen->valid());
var_dump($gens[1]->valid());