- var_dump: documentation ( source)
<?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());