- var_dump: documentation ( source)
<?php
final class Container{
private $callables = [];
public function __set(string $name,$value){
if($value instanceof Closure){
$this->callables[$name] = $value;
}
}
public function __call(string $method, array $args){
if(isset($this->callables[$method])){
$callable = $this->callables[$method];
$callable($args);
}
}
}
$container = new Container();
$container->demo = function(){
return new Container();
};
var_dump($container->demo());