3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function gen_one_to_three() { for ($i = 1; $i <= 3; $i++) { $a = yield; echo $a; } } $generator = gen_one_to_three(); foreach ($generator as $value) { $generator->send('cheese'); echo "$value\n"; }
Output for 5.5.0 - 7.1.10
cheese cheese
Output for 4.3.0 - 4.3.10, 4.4.0 - 5.4.45
Notice: Use of undefined constant yield - assumed 'yield' in /in/6oF4Z on line 6 yield Notice: Use of undefined constant yield - assumed 'yield' in /in/6oF4Z on line 6 yield Notice: Use of undefined constant yield - assumed 'yield' in /in/6oF4Z on line 6 yield Warning: Invalid argument supplied for foreach() in /in/6oF4Z on line 12
Output for 4.3.11
Notice: Use of undefined constant yield - assumed 'yield' in /in/6oF4Z on line 6 yield Notice: Use of undefined constant yield - assumed 'yield' in /in/6oF4Z on line 6 yield Notice: Use of undefined constant yield - assumed 'yield' in /in/6oF4Z on line 6 yield