3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php declare(strict_types=1); final class Container{ private $callables = array(); public function __set($name,$value){ if($value instanceof Closure){ $this->callables[$name] = $value; } } public function __call($method, array $args){ if(isset($this->callables[$method])){ $callable = $this->callables[$method]; return call_user_func_array($callable,$args); } } } $container = new Container(); $container->demo = function(){ return new Container(); }; var_dump($container->demo());
based on JAX33
Output for 7.0.0 - 7.2.0
object(Container)#3 (1) { ["callables":"Container":private]=> array(0) { } }
Output for 5.3.20 - 5.6.28
Warning: Unsupported declare 'strict_types' in /in/Yr8vM on line 2 object(Container)#3 (1) { ["callables":"Container":private]=> array(0) { } }