Php Lineage constructor method, member variable

Source: Internet
Author: User
PHP Inheritance constructor method, member variable

found that they have been relatively vague on these concepts, summed up as follows:

?

1. When a subclass does not have a constructor method, the constructor of the parent class is called by default

?

2. If the subclass has a constructor method, the constructor of the parent class is not called, and the member variable of the parent class is overwritten, and if it is to be called, it is parent::__construct ();

?

3. Member variables and methods of the parent class are inherited by default by the quilt class

?

eg

    Class a{public        $a = array ();        Public $b = ';        Public Function __construct () {            $this->a = Array (' A ', ' B ', ' C ');            $this->b = ' Bobby ';            echo ' construct '. "\ n";        }        Public function Get () {            print_r ($this->a);        }    }    Class B extends a{public        function __construct () {            parent::__construct ();            $this->c = ' CC ';        }        Public function Get () {            Array_push ($this->a, ' d ');            Print_r ($this->a);            echo $this->c;        }        Public Function Getb () {            echo Parent:: $this->b;        }    }    $a = new A ();    $b = new B ();    $b->get ();    $b->getb ();
  • 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.