Problems in the php Manual

Source: Internet
Author: User
{Code...} Could you please explain this piece of code, why is this output at the end?
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

Please explain the code below. Why is the output at the end?

Reply content:
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

Please explain the code below. Why is the output at the end?

The method of private visibility does not exist, so in which class the method is called, it is to call the private method corresponding to that class (if it does not exist, an error is reported)

The call to the inheritance Chain Method of the potholes will confuse many people ..

It is recommended to look at c speech implementation class and inheritance... you will understand a lot.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.