Q:

PHP manual OOP visibility example - can someone explain it

I saw this in the PHP OOP manual http://www.php.net/manual/en/language.oop5.visibility.php and I can't get my head around why the output is not: 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

A:

It's all about the visibility of the variables / methods.
You'll notice that in the Bar class, the method testPrivate() is private.  That means that ONLY itself can access that method.  No children.
So when Foo extends Bar, and then asks to run the test() method, it does two things:

It overrides the testPublic() method because it's public, and Foo has the right to override it with it's own version.
It calls test() on Bar (since test() only exists on Bar()).

testPrivate() is not overridden, and is part of the class that holds test().  Therefore, Bar::testPrivate is printed.
testPublic() is overridden, and is part of the inheriting class.  Therefore, Foo::testPublic is printed.

