3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?hh function fibonacci() { $a = 0; $b = 1; return function() use (&$a, &$b) { $c = $a; $a = $b; $b += $c; return $c; }; } $fib = fibonacci(); for ($i = 0; $i < 10; $i++) { echo $fib(), PHP_EOL; }
based on Vb6QW
Output for hhvm-3.10.0 - 3.12.0
0 1 1 2 3 5 8 13 21 34
Output for 5.3.0 - 5.4.32
<?hh function fibonacci() { $a = 0; $b = 1; return function() use (&$a, &$b) { $c = $a; $a = $b; $b += $c; return $c; }; } $fib = fibonacci(); for ($i = 0; $i < 10; $i++) { echo $fib(), PHP_EOL; }