3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function ping_pong() { for ($i = 1; $i <= 10; $i++) { echo 'a' . $i; $val = (yield $i); echo 'b' . $i; echo 'ping: ' . $val . PHP_EOL; echo 'c' . $i; } } $generator = ping_pong(); foreach ($generator as $value) { echo 'pong: ' . $generator->send($value) . PHP_EOL; }
Output for 5.5.24 - 5.6.28, 7.0.0 - 7.1.0
a1b1ping: 1 c1a2pong: 2 b2ping: c2a3b3ping: 3 c3a4pong: 4 b4ping: c4a5b5ping: 5 c5a6pong: 6 b6ping: c6a7b7ping: 7 c7a8pong: 8 b8ping: c8a9b9ping: 9 c9a10pong: 10 b10ping: c10
Output for hhvm-3.10.0 - 3.12.0
a1b1ping: 1 c1a2pong: b2ping: c2a3b3ping: 3 c3a4pong: b4ping: c4a5b5ping: 5 c5a6pong: b6ping: c6a7b7ping: 7 c7a8pong: b8ping: c8a9b9ping: 9 c9a10pong: b10ping: c10
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$i' (T_VARIABLE) in /in/4jsPq on line 8
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/4jsPq on line 8
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/4jsPq on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/4jsPq on line 8
Process exited with code 255.