Questions about access control in PHP class and object private

  • 2020-05-26 07:57:09
  • OfStack

 
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 

Why would line 1 print Bar::testPrivate?
1 some information:
https://www.ofstack.com/article/31709.htm
Also on the php website, one of the contributors' responses to this code was found:
http://www.php.net/manual/zh/language.oop5.visibility.php#87413

Related articles: