3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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());
based on jOiLQ
Output for 7.0.0 - 7.2.0
NULL
Output for 5.4.10 - 5.6.28
Catchable fatal error: Argument 1 passed to Container::__set() must be an instance of string, string given in /in/hletM on line 6
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/hletM on line 4
Process exited with code 255.