復制代碼 代碼如下:
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
為啥第一行會輸出Bar::testPrivate呢?
一些資料:
http://www.jb51.net/article/31709.htm
還有php官網上,關於這段代碼的貢獻者回復中,也找到了一條:
http://www.php.net/manual/zh/language.oop5.visibility.php#87413