What are the special meanings of constructors in PHP that call unrelated classes?

Source: Internet
Author: User
Tags yii
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);    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.