复制代码 代码如下:

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.uoften.com/article/31709.htm
还有php官网上,关于这段代码的贡献者回复中,也找到了一条:
http://www.php.net/manual/zh/language.oop5.visibility.php#87413

点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部