3v4l.org

run code in 300+ PHP versions simultaneously
<?php function del1() { yield 1; return 'hi'; } function del2() { yield 2; } function g_master() { $x = yield from del1(); echo "lv ", $x, "\n"; yield 3; $y = yield from del2(); echo "lv2 ", $y, "\n"; yield 4; return 5; } foreach (g_master() as $x) { echo $x, "\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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
1 lv hi 3 2 lv2 4
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Fatal error: Generators cannot return values using "return" in /in/Eb1PT on line 5
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '1' (T_LNUMBER) in /in/Eb1PT on line 4
Process exited with code 255.

preferences:
302.42 ms | 401 KiB | 376 Q