note 126385 added to language.oop5.late-static-bindings
| From: | backnot at main dot php dot net | Date: | Sat, 04 Sep 2021 11:07:34 +0000 |
| Subject: | note 126385 added to language.oop5.late-static-bindings | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216857@lists.php.net to get a copy of this message | ||
In the above example (#3) in order to make it work, you can change the child's method from
'private' to 'protected' (or public) and it will be called through
'static'.
<?php
class A {
private function foo() {
echo "success!\n";
}
public function test() {
$this->foo();
static::foo();
}
}
class B extends A {
/* foo() will be copied to B, hence its scope will still be A and
* the call be successful */
}
class C extends A {
protected function foo() { //note the change here
echo 'hello world!';
}
}
$b = new B();
$b->test();
$c = new C();
$c->test(); // 'success' 'hello world'
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 212.21.150.119)
----
Manual Page -- https://php.net/manual/en/language.oop5.late-static-bindings.php
Edit -- https://main.php.net/note/edit/126385
Del: integrated -- https://main.php.net/note/delete/126385/integrated
Del: useless -- https://main.php.net/note/delete/126385/useless
Del: bad code -- https://main.php.net/note/delete/126385/bad+code
Del: spam -- https://main.php.net/note/delete/126385/spam
Del: non-english -- https://main.php.net/note/delete/126385/non-english
Del: in docs -- https://main.php.net/note/delete/126385/in+docs
Del: other reasons-- https://main.php.net/note/delete/126385
Reject -- https://main.php.net/note/reject/126385
Search -- https://main.php.net/manage/user-notes.php