3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $called = false; $_n_times_closure = function ($times) { return function (\Closure $closure) use ($times) { return function (...$parameters) use (&$times) { if (!$times) { return; } $times--; return $closure(...$parameters); }; }; }; $_once = $n_times_closure(1); $called = 0; $current_time = $_once(function() use (&$called) { return time(); }); var_dump($called, $current_time(), $called, $current_time(), $called);
based on lNdsp
Output for 7.0.0 - 7.2.0
Notice: Undefined variable: n_times_closure in /in/d6oW1 on line 18 Fatal error: Uncaught Error: Function name must be a string in /in/d6oW1:18 Stack trace: #0 {main} thrown in /in/d6oW1 on line 18
Process exited with code 255.
Output for 5.6.0 - 5.6.28
Notice: Undefined variable: n_times_closure in /in/d6oW1 on line 18 Fatal error: Function name must be a string in /in/d6oW1 on line 18
Process exited with code 255.
Output for 5.4.0 - 5.5.38
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/d6oW1 on line 7
Process exited with code 255.