我在PHP OOP手冊http://www.php.net/manual/en/language.oop5.visibility.php看到這個,爲什麼輸出不是我不能讓我的周圍頭:富:: testPrivate富:: testPublicPHP手冊OOP知名度的例子 - 有人可以解釋它
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
提示:如果將'private'更改爲'protected',您將獲得所需的輸出。閱讀有關訪問修飾符。 – 2012-02-24 15:59:11
檢查這個線程。第一個答案幫助了我很多。 http://stackoverflow.com/questions/12794290/php-manual-visibilty-example-confused – Sam 2013-03-06 05:31:03
檢查此線程。第一個答案幫助了我很多。 http://stackoverflow.com/questions/12794290/php-manual-visibilty-example-confused – Sam 2013-03-06 05:32:09