3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function foo() { yield 1; yield 2; return 42; } $bar = foo(); foreach ($bar as $val) { var_dump($val); } var_dump($bar->getReturn()); var_dump($bar->current()); $bar->send(21); var_dump($bar->current()); var_dump($bar->getReturn());
based on JR6Jk
Output for 7.0.0 - 7.3.1
int(1) int(2) int(42) NULL NULL int(42)
Output for 5.5.0 - 5.6.38
Fatal error: Generators cannot return values using "return" in /in/82tUs 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/82tUs on line 3
Process exited with code 255.