I'm looking at the startup process of Yii2, where application's parent constructor is written like this;
I want to ask the last sentence component::__construct ($config) What is the special meaning of the call here?
public function __construct($config = []) { Yii::$app = $this; $this->setInstance($this); $this->state = self::STATE_BEGIN; $this->preInit($config); $this->registerErrorHandler($config); Component::__construct($config); }
Mainly in the process of tracking code, there is a problem is not understood,
Component::__construct ($config)---->object::__construct ($config)--->yii::configure ($this, $config)
That's how it's handled in Yii::configure:
public static function configure($object, $properties) { foreach ($properties as $name => $value) { $object->$name = $value; } return $object; }
This is actually the final call to the appropriate setter function, where $config generally contains the set of components, so it is called to the Setcomponents function, which application the parent class definition, so here $ Why can the this instance be called to a application function?
$this is clearly an example of component, so I can not understand, PHP Foundation did not learn
Reply content:
I'm looking at the startup process of Yii2, where application's parent constructor is written like this;
I want to ask the last sentence component::__construct ($config) What is the special meaning of the call here?
public function __construct($config = []) { Yii::$app = $this; $this->setInstance($this); $this->state = self::STATE_BEGIN; $this->preInit($config); $this->registerErrorHandler($config); Component::__construct($config); }
Mainly in the process of tracking code, there is a problem is not understood,
Component::__construct ($config)---->object::__construct ($config)--->yii::configure ($this, $config)
That's how it's handled in Yii::configure:
public static function configure($object, $properties) { foreach ($properties as $name => $value) { $object->$name = $value; } return $object; }
This is actually the final call to the appropriate setter function, where $config generally contains the set of components, so it is called to the Setcomponents function, which application the parent class definition, so here $ Why can the this instance be called to a application function?
$this is clearly an example of component, so I can not understand, PHP Foundation did not learn
Application calls the build method of component, component inherits the method of constructing the object class where the application function is called.
Suddenly remembered, application extends Module extends Servicelocator extends Component extends Object
So the component::__construct inside the application constructor is simply the constructor of the parent class that calls the multi-layered inheritance, so you can understand that the $this in object ultimately points to the application instance.
public function __construct($config = []) { Yii::$app = $this; $this->setInstance($this); $this->state = self::STATE_BEGIN; $this->preInit($config); $this->registerErrorHandler($config); Component::__construct($config); }