3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function gen1() { $x = yield 1; echo "Got $x from a yield\n"; $x = yield 2; echo "Got $x from a yield\n"; $x = yield 3; echo "Got $x from a yield\n"; } function yf($iter) { yield from $iter; } function yfr($iter) { $isSubgenerator = $iter instanceof Generator; foreach($iter as $val) { yield $val; } } // $g = yfr(gen1()); $g = yf(gen1()); $g->next(); var_dump($g->current()); $g->send(10); var_dump($g->current()); $g->send(20); var_dump($g->current());
based on 7RSGi
Output for 7.0.0 - 7.2.0
Got from a yield int(2) Got 10 from a yield int(3) Got 20 from a yield NULL
Output for 5.4.0 - 5.6.28
Parse error: syntax error, unexpected '1' (T_LNUMBER) in /in/XvsLg on line 4
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected T_LNUMBER in /in/XvsLg on line 4
Process exited with code 255.