3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen(int $x) { $x = yield $x + 1; $x = yield $x + 2; $x = yield $x + 3; $x = yield $x + 4; } $gen = gen(5); $assertions = [ ['expect' => 6], ['send' => 1, 'expect' => 3], ['send' => 5, 'expect' => 8], ['send' => 3, 'expect' => 7], ]; foreach($assertions as $assertion) { if(!array_key_exists('send', $assertion)) { echo '(Received / Initial Assertion / Whatever) ' . $gen->current() . PHP_EOL; continue; } echo $assertion['expect'] . ' === ' . $gen->send($assertion['send']) . PHP_EOL; }
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
(Received / Initial Assertion / Whatever) 6 3 === 3 8 === 8 7 === 7

preferences:
146.59 ms | 408 KiB | 5 Q