| Newsgroups |
php.notes |
| Message-ID |
<[email protected]> |
Documentation says: Private methods of a parent class are not accessible to a child class. As a result, "child classes may reimplement a private method themselves without regard for normal inheritance rules."
So it is not very obvious what this will output:
<?php
class Bar {
private function one() {
echo "Bar::one()\n";
}
public function run() {
echo "Bar::run()\n";
$this->one();
}
}
class Foo extends Bar {
private function one() {
echo "Foo::one()\n";
}
}
(new Foo())->run();
?>
Bar::run()
Bar::one()
A common sense next step would be to try make the method "one" in Foo public,
but this does not work either if the caller is the parent class.
For the parent to be able to direct the child class
both need to be public or you must call the method explicitly on the child class:
<?php
(new Foo())->one();
?>
----
Server IP: 206.189.2.9
Probable Submitter: 85.85.73.134
----
Manual Page -- https://php.net/manual/en/language.oop5.inheritance.php
Edit -- https://main.php.net/note/edit/130628
Del: integrated -- https://main.php.net/note/delete/130628/integrated
Del: useless -- https://main.php.net/note/delete/130628/useless
Del: bad code -- https://main.php.net/note/delete/130628/bad+code
Del: spam -- https://main.php.net/note/delete/130628/spam
Del: non-english -- https://main.php.net/note/delete/130628/non-english
Del: in docs -- https://main.php.net/note/delete/130628/in+docs
Del: other reasons-- https://main.php.net/note/delete/130628
Reject -- https://main.php.net/note/reject/130628
Search -- https://main.php.net/manage/user-notes.php