3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
b Deprecated: Creation of dynamic property DICT::$c is deprecated in /in/eAa12 on line 32 Fatal error: Uncaught Error: Attempt to assign property "d" on null in /in/eAa12:32 Stack trace: #0 {main} thrown in /in/eAa12 on line 32
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
b Fatal error: Uncaught Error: Attempt to assign property "d" on null in /in/eAa12:32 Stack trace: #0 {main} thrown in /in/eAa12 on line 32
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
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.5.24 - 5.5.35, 5.6.8 - 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.

preferences:
183.37 ms | 402 KiB | 228 Q