note 126913 deleted from language.oop5.decon by cmb

From: Date: Thu, 10 Mar 2022 17:14:23 +0000
Subject: note 126913 deleted from language.oop5.decon by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-217706@lists.php.net to get a copy of this message
Note Submitter: mmulej at gmail dot com ---- If both parent and child classes have a method with the same name defined, and it is called in parent's constructor, using parent::__construct() will call the method in the child. <?php class A { public function __construct() { $this->method(); } public function method() { echo 'A' . PHP_EOL; } } class B extends A { public function __construct() { parent::__construct(); } } class C extends A { public function __construct() { parent::__construct(); } public function method() { echo 'C' . PHP_EOL; } } $b = new B; // A $c = new C; // C ?>

« previous php.notes (#217706) next »