在PHP中,你的意思是函数重载和函数重写.它们两者有什么区别?无法弄清楚它们之间有什么区别.
我在PHP OOP手册http://www.php.net/manual/en/language.oop5.visibility.php中看到了这个,我无法理解为什么输出不是:Foo :: 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
Run Code Online (Sandbox Code Playgroud)