-
- class Bar
- {
- public function test() {
- $this->testPrivate();
- $this->testPublic();
- }
- public function testPublic() {
- echo "Bar::testPublicn";
- }
- private function testPrivate() {
- echo "Bar::testPrivaten";
- }
- }
- class Foo extends Bar
- {
- public function testPublic() {
- echo "Foo::testPublicn";
- }
- private function testPrivate() {
- echo "Foo::testPrivaten";
- }
- }
- $myFoo = new foo();
- $myFoo->test(); // Bar::testPrivate
- // Foo::testPublic
复制代码
为什么第一行会输出Bar::testPrivate呢?
一些资料:
本文夹中的7中的内容
在php官网上,关于这段代码的贡献者回复:
http://www.php.net/manual/zh/language.oop5.visibility.php#87413
|