3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function gen($x) { yield $x; return $x * 5; } function yf() { $x = yield from gen(1); echo "x is $x\n"; $y = yield from gen(2); echo "y is $y\n"; return yield from gen(42); } $g = yf(); foreach($g as $val) { var_dump($val); } echo "====================\n"; var_dump($g->getReturn());
based on REb9R
Output for 7.0.0 - 7.2.0
int(1) x is 5 int(2) y is 10 int(42) ==================== int(210)
Output for 5.5.24 - 5.6.28
Fatal error: Generators cannot return values using "return" in /in/tHA6N on line 5
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$x' (T_VARIABLE) in /in/tHA6N on line 4
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected T_VARIABLE in /in/tHA6N on line 4
Process exited with code 255.