3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen1() { echo "Beginning gen1\n"; $x = yield 1; echo "Sup!\n"; $y = yield 2; var_dump($x + $y); } function yfgenerator() { echo "Beginning yfgenerator\n"; yield from gen1(); echo "Dawg\n"; yield from gen1(); } 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(yfgenerator()); echo "====================\n"; //sendingTest(yfiterator()); sendingTest(yfgenerator()); echo "Done with all tests\n";
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
About to start iteration Beginning yfgenerator Beginning gen1 Iteration! int(0) int(1) Sup! Iteration! int(1) int(2) int(0) Dawg Beginning gen1 Iteration! int(0) int(1) Sup! Iteration! int(1) int(2) int(0) Done with iteration ==================== Beginning yfgenerator Beginning gen1 Sup! int(2) int(30) Dawg Beginning gen1 int(1) Done with all tests
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 About to start iteration Beginning yfgenerator Beginning gen1 Iteration! int(0) int(1) Sup! Iteration! int(1) int(2) int(0) Dawg Beginning gen1 Iteration! int(0) int(1) Sup! Iteration! int(1) int(2) int(0) Done with iteration ==================== Beginning yfgenerator Beginning gen1 Sup! int(2) int(30) Dawg Beginning gen1 int(1) Done with all tests
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Parse error: syntax error, unexpected '1' (T_LNUMBER) in /in/AXDaE on line 5
Process exited with code 255.

preferences:
263.94 ms | 401 KiB | 329 Q