3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function stack(... $items) { foreach ($items as $item) { if ($next = yield $item) { yield from stack(... $next); } else { yield $next; } } } $items = [1,2,3]; $stack = stack(...$items); foreach ($stack as $item) { if ($item == 1) { $stack->send(['negate', -$item]); // push something onto the stack } if ($item == 2) { continue; // remove something from the stack } if ($item == 3) { $stack->send(['exponential', $item ** 2]); // push something onto the stack } if (isset($item)) { var_dump($item); } }
based on grEUi
Output for 7.0.30 - 7.3.0rc3
int(1) int(-1) int(3) int(9)
Output for hhvm-3.22.0
Fatal error: Uncaught Error: syntax error, unexpected T_YIELD in /in/oUIJE:-1 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
Fatal error: Uncaught Error: syntax error, unexpected T_YIELD in /in/oUIJE:7 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.30
Parse error: syntax error, unexpected '$item' (T_VARIABLE) in /in/oUIJE on line 7
Process exited with code 255.