3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class DICT { // список объектов private $objects = []; // создание объекта public function __set($name, $value){ if( !isset( $this->objects[$name] ) ){ $this->objects[$name] = $value; }else{ echo 'DICT name "'. $name .'" is already exist!'; } } // вызов объекта public function __call($name, $args){ if( isset( $this->objects[$name] ) ){ return call_user_func_array($this->objects[$name], $args); }else{ echo 'DICT name "'. $name .'" is not exist!'; } } } $a = new DICT; $a->b = function(){ echo 'b'; }; $a->c = new DICT; $a->b(); // работает $a->c->d = function(){ echo 'd'; }; $a->c->d();
Output for 7.0.0 - 7.2.0
b Warning: Creating default object from empty value in /in/eAa12 on line 32 Fatal error: Uncaught Error: Call to undefined method stdClass::d() in /in/eAa12:33 Stack trace: #0 {main} thrown in /in/eAa12 on line 33
Process exited with code 255.
Output for 5.4.11 - 5.6.28
b Warning: Creating default object from empty value in /in/eAa12 on line 32 Fatal error: Call to undefined method stdClass::d() in /in/eAa12 on line 33
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/eAa12 on line 6
Process exited with code 255.