Home >Backend Development >PHP Tutorial >Questions about private access control in php classes

Questions about private access control in php classes

WBOY
WBOYOriginal
2016-07-25 09:03:42942browse
  1. class Bar
  2. {
  3. public function test() {
  4. $this->testPrivate();
  5. $this->testPublic();
  6. }
  7. public function testPublic() {
  8. echo "Bar::testPublicn";
  9. }
  10. private function testPrivate() {
  11. echo "Bar::testPrivate";
  12. }
  13. }
  14. class Foo extends Bar
  15. {
  16. public function testPublic() {
  17. echo "Foo: :testPublicn";
  18. }
  19. private function testPrivate() {
  20. echo "Foo::testPrivaten";
  21. }
  22. }
  23. $myFoo = new foo();
  24. $myFoo->test(); // Bar:: testPrivate
  25. // Foo::testPublic
Copy code

Why does Bar::testPrivate appear in the first line? some documents: Contents of 7 in this folder

On the PHP official website, the contributors about this code responded: http://www.php.net/manual/zh/language.oop5.visibility.php#87413



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