3v4l.org

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