You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
I would like to improve the documentation by adding the following example:
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();
the output is
Bar::run()
Bar::one()
Which is not really what I would expect to happen since I'm calling Foo, which inherits ::run() and I expected run() to happen within Foo and not Bar. So I presume this is a feature, but how do I extend Bar without modifying it (let's say I cannot) and override ::one() ?
The solution I can see so far is that both need to be public.
Thank you.
The text was updated successfully, but these errors were encountered:
From manual page: https://php.net/language.oop5.inheritance
regarding the section:
I would like to improve the documentation by adding the following example:
the output is
Which is not really what I would expect to happen since I'm calling Foo, which inherits ::run() and I expected run() to happen within Foo and not Bar. So I presume this is a feature, but how do I extend Bar without modifying it (let's say I cannot) and override ::one() ?
The solution I can see so far is that both need to be public.
Thank you.
The text was updated successfully, but these errors were encountered: