Home > Backend Development > PHP Tutorial > PHP类与对象中的private访问控制的疑问_PHP

PHP类与对象中的private访问控制的疑问_PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 12:09:11
Original
986 people have browsed it
复制代码 代码如下:
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

为啥第一行会输出Bar::testPrivate呢?
一些资料: 
http://www.bitsCN.com/article/31709.htm
还有php官网上,关于这段代码的贡献者回复中,也找到了一条:
http://www.php.net/manual/zh/language.oop5.visibility.php#87413
Related labels:
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
Latest Issues
javascript - safari private browsing
From 1970-01-01 08:00:00
0
0
0
Are there any better private git repositories?
From 1970-01-01 08:00:00
0
0
0
What is the git-bower private repository?
From 1970-01-01 08:00:00
0
0
0
Why is private mail triggered?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template