class Bar { public function test() { $this->testPrivate(); $this->testPublic(); } public function testPublic() { echo "Bar::testPublic\n"; } private function testPrivate() { echo "Bar::testPrivate\n"; }}class Foo extends Bar { public function testPublic() { echo "Foo::testPublic\n"; } private function testPrivate() { echo "Foo::testPrivate\n"; }}$myFoo = new foo();$myFoo->test(); // Bar::testPrivate // Foo::testPublic
Ask the great God to explain this code, the last side of the output why is this?
Reply content:
class Bar { public function test() { $this->testPrivate(); $this->testPublic(); } public function testPublic() { echo "Bar::testPublic\n"; } private function testPrivate() { echo "Bar::testPrivate\n"; }}class Foo extends Bar { public function testPublic() { echo "Foo::testPublic\n"; } private function testPrivate() { echo "Foo::testPrivate\n"; }}$myFoo = new foo();$myFoo->test(); // Bar::testPrivate // Foo::testPublic
Ask the great God to explain this code, the last side of the output why is this?
The method of private visibility does not exist, so the calling method in which class is called the private method corresponding to that class (if it does not exist, the error is reported)
The method call of the pit father's inheritance chain: Would have knocked a lot of people around.
It is recommended to look at C speech implementation class and inheritance ... You'll understand a lot.