3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.25, 7.3.0 - 7.3.12, 7.4.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.4.45, 5.5.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.

preferences:
158.43 ms | 402 KiB | 179 Q