3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function count_to_ten() { $t = yield from seven_eight(); var_dump($t); return 'ok'; } function seven_eight() { foreach ([1, 2, 3] as $k => $v) {yield $v;} } $gen = count_to_ten(); foreach ($gen as $k => $num) { echo $gen->send('t'); echo "\n-$k -> $num \n"; } var_dump( $gen->getReturn());
based on BFsHh
Output for 7.0.0 - 7.2.6
2 -0 -> 1 NULL -2 -> 3 string(2) "ok"
Output for hhvm-3.15.4
-0 -> 1 NULL -2 -> 3 Fatal error: Uncaught exception 'Exception' with message 'Generator is already finished' in /in/O3RbP:19 Stack trace: #0 /in/O3RbP(19): Generator->next() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected 'from' (T_STRING) in /in/O3RbP on line 5
Process exited with code 255.