Questions about private access control in PHP classes and objects_PHP Tutorial

WBOY
Release: 2016-07-21 15:15:09
Original
726 people have browsed it

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...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template