3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function gen1() { $x = yield 1; echo "Sup!\n"; $y = yield 2; var_dump($x + $y); } function yfgenerator() { yield from gen1(); echo "Dawg\n"; yield from gen1(); } function yfeiterator() { $arr = [1, 2, 3]; foreach($arr as $val) { yield $val; } } function yfiterator() { yield from []; yield from [1, 2, 3]; /**/ yield from array( "first" => 1, "second" => 2, "third" => 3, ); /**/ } function iterationTest($g) { echo "About to start iteration\n"; foreach($g as $key => $val) { echo "Iteration!\n"; var_dump($key); var_dump($val); } echo "Done with iteration\n"; } function sendingTest($g) { $g->send(10); var_dump($g->current()); $g->send(20); var_dump($g->current()); } //iterationTest(yfiterator()); // iterationTest(gen1()); sendingTest(yfiterator()); sendingTest(yfgenerator()); echo "Done with all tests\n";
Output for 7.0.0 - 7.2.0
int(2) int(3) Sup! int(2) int(30) Dawg int(1) Done with all tests
Output for 5.4.0 - 5.6.28
Parse error: syntax error, unexpected '1' (T_LNUMBER) in /in/gc8JT 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/gc8JT on line 4
Process exited with code 255.