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