note 126913 added to language.oop5.decon
| From: | mmulej at gmail dot com | Date: | Thu, 10 Mar 2022 16:37:20 +0000 |
| Subject: | note 126913 added to language.oop5.decon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217704@lists.php.net to get a copy of this message | ||
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
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 89.142.234.171)
----
Manual Page -- https://php.net/manual/en/language.oop5.decon.php
Edit -- https://main.php.net/note/edit/126913
Del: integrated -- https://main.php.net/note/delete/126913/integrated
Del: useless -- https://main.php.net/note/delete/126913/useless
Del: bad code -- https://main.php.net/note/delete/126913/bad+code
Del: spam -- https://main.php.net/note/delete/126913/spam
Del: non-english -- https://main.php.net/note/delete/126913/non-english
Del: in docs -- https://main.php.net/note/delete/126913/in+docs
Del: other reasons-- https://main.php.net/note/delete/126913
Reject -- https://main.php.net/note/reject/126913
Search -- https://main.php.net/manage/user-notes.php