PHP面向对象编程哎呀问题

I am trying to implement a code somewhat like below but not able to understand one issue, as per my understanding it should have printed the data like this:

Foo::testPrivate
Foo::testPublic

But its displaying output as ::

Bar::testPrivate 
Foo::testPublic

The code is::

class Bar 
{
    public function test() {
        $this->testPrivate();
        $this->testPublic();
    }

    public function testPublic() {
        echo "Bar::testPublic
";
    }

    private function testPrivate() {
        echo "Bar::testPrivate
";
    }
}

class Foo extends Bar 
{
    public function testPublic() {
        echo "Foo::testPublic
";
    }

    private function testPrivate() {
        echo "Foo::testPrivate
";
    }
}

$myFoo = new Foo();
$myFoo->test();

Can somebody please explain this?

As per my Understanding

  • Displaying output is right because of you are created object of "Foo" class and then after call test() function is inside the "Bar" class

  • In test() function of Bar class is call testPrivate() using "this" keyword so call the function in same class and testPrivate() is also private so that's why display result like :

Bar::testPrivate
Foo::testPublic

  • Make changes to private function testPrivate() { } to public function testPrivate() in both the class for displayed your accepted result
  • Result after made this changes is :

Foo::testPrivate
Foo::testPublic