0
我想实现一个代码有点像下面,但无法理解一个问题,按我的理解,它应该已经印像这样的数据:PHP面向对象编程哎呀问题
Foo::testPrivate
Foo::testPublic
但它的显示输出::
Bar::testPrivate
Foo::testPublic
的代码::
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' – Peon
小孩不能覆盖私人函数。 –
The docs:http://php.net/manual/en/language.oop5.visibility.php –