3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function count_to_ten() { foreach (['f1', 'f2', 'f3'] as $file) { $t = yield; if ($t == 't') { } echo '$'.($t)."\n"; yield from seven_eight(); } return 'ok'; } function seven_eight() { foreach ([1, 2, 3] as $k => $v) { yield $v; } } $gen = count_to_ten(); foreach ($gen as $k => $num) { echo "\n-$k -> $num \n";echo $gen->send('t'); } var_dump( $gen->getReturn());
based on j5Asn
Output for 7.0.0 - 7.3.0rc3
-0 -> $t 1 -1 -> 2 3 -1 -> $t 1 -1 -> 2 3 -2 -> $t 1 -1 -> 2 3string(2) "ok"
Output for hhvm-3.15.4
-0 -> $t -1 -> 2 -1 -> $t -1 -> 2 -2 -> $t -1 -> 2 string(2) "ok"
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected 'seven_eight' (T_STRING) in /in/Q81Te on line 10
Process exited with code 255.