3v4l.org

run code in 300+ PHP versions simultaneously
<?php $foo = function () { $cache = null; $closure = function () use (&$cache) { if ($cache === null) { $instance = new StdClass; $instance->param = 0; $cache = $instance; } $cache->param += 1; return $cache; }; return $closure; }; $provider = $foo(); var_dump($provider()); var_dump($provider());

preferences:
25.1 ms | 404 KiB | 5 Q