class method visibility
| From: | Jeremy Wei | Date: | Thu, 15 Mar 2012 10:43:17 +0000 |
| Subject: | class method visibility | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-317015@lists.php.net to get a copy of this message | ||
I read the manual about method visibility, but i can't understand the
code below:
<?php
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
?>
in class Bar's method test, why "$this->testPrivate();" invoked
testPrivate method of class Bar,
but not the testPrivate of class Foo? here $this shoud be the
reference of the instance of class Foo,
isn't it?
--
JeremyWei(魏志锋,字静之)
Mob: 18914495716
新浪微博:@JeremyWei
QQ: 327493482
Home: www.weizhifeng.net
Less is more