<?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();
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.
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.