3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /** @return Generator */ function example() { for ($i = 0; $i < 5; $i += 1) { $answer = (yield $i * 2); echo "received: $answer\n"; } } $gen = example(); foreach ($gen as $x) { echo "sending $x\n"; $gen->send($x); }
Output for 5.5.0 - 5.6.30, 7.0.0 - 7.2.6
sending 0 received: 0 received: sending 4 received: 4 received: sending 8 received: 8
Output for hhvm-3.22.0
sending 0 received: 0 received: sending 4 received: 4 received: sending 8 received: 8 Fatal error: Uncaught exception 'Exception' with message 'Generator is already finished' in /in/bfg64:-1 Stack trace: #0 /in/bfg64(-1): Generator->next() #1 {main}
Process exited with code 255.
Output for hhvm-3.10.1 - 3.21.3
sending 0 received: 0 received: sending 4 received: 4 received: sending 8 received: 8 Fatal error: Uncaught exception 'Exception' with message 'Generator is already finished' in /in/bfg64:15 Stack trace: #0 /in/bfg64(15): Generator->next() #1 {main}
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$i' (T_VARIABLE) in /in/bfg64 on line 6
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected T_VARIABLE in /in/bfg64 on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_VARIABLE in /in/bfg64 on line 6
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/bfg64 on line 6
Process exited with code 255.