Home  >  Article  >  Backend Development  >  Questions about private access control in PHP classes and objects_PHP Tutorial

Questions about private access control in PHP classes and objects_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:15:09724browse

Copy code The code is as follows:

class Bar
{
public function test() {
$this- >testPrivate();
$this->testPublic();
}
public function testPublic() {
echo "Bar::testPublicn";
}
private function testPrivate() {
echo "Bar::testPrivaten";
}
}
class Foo extends Bar
{
public function testPublic() {
echo "Foo ::testPublicn";
}
private function testPrivate() {
echo "Foo::testPrivaten";
}
}
$myFoo = new foo();
$myFoo->test(); // Bar::testPrivate
// Foo::testPublic

Why is Bar::testPrivate output in the first line?
Some information:
http://www.jb51.net/article/31709.htm
There is also a reply from the contributor about this code on the PHP official website:
http://www.php.net/manual/zh/language.oop5.visibility.php#87413

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326157.htmlTechArticleCopy the code The code is as follows: class Bar { public function test() { $this-testPrivate(); $this- testPublic(); } public function testPublic() { echo "Bar::testPublicn"; } private functi...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn