I have confused from an example in php manual. It's about visibility. Here is the example.
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();
?>
http://www.php.net/manual/en/language.oop5.visibility.php
This example outputs
Bar::testPrivate
Foo::testPublic
Please can you explain how this happen?
why both testPublic()
are not called?
I put a var_dump($this)
in Bar class construct. It prints object(Foo)[1]
. The thing I know is private properties can be called withing same class.
Then how "Bar::testPrivate
" is called?