3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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());
Output for 7.0.1 - 7.2.0
Current: int(1) Current: int(2) Current: int(3) Current: int(4) Current: int(5) Current: int(5) bool(true)
Output for 7.0.0
Current: int(1) Current: int(2) Current: int(3) Current: int(4) Current: int(5) Current: NULL bool(false)
Output for 5.5.24 - 5.6.28
Parse error: syntax error, unexpected '$gen' (T_VARIABLE) in /in/JFrIb on line 10
Process exited with code 255.
Output for 5.4.9 - 5.4.45
Parse error: syntax error, unexpected '1' (T_LNUMBER) in /in/JFrIb on line 3
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected T_LNUMBER in /in/JFrIb on line 3
Process exited with code 255.