An example of php access control interview questions

WBOY
Release: 2016-07-25 08:54:32
Original
726 people have browsed it
  1. class Foo
  2. {
  3. private $name = 'hdj';
  4. public function getName(){
  5. return $this->name;
  6. }
  7. }
  8. class Bar extends Foo
  9. {
  10. public $name = 'deeka';
  11. }
  12. $bar = new Bar;
  13. var_dump($bar->name);
  14. var_dump($bar->getName());
Copy code

php access control instructions: Access control to properties or methods is achieved by adding the keywords public, protected or private in front. Class members defined by public can be accessed from anywhere; Class members defined by protected can be accessed by subclasses and parent classes of the class in which they are located (of course, the class in which the member is located can also be accessed); Class members defined by private can only be accessed by the class in which they are located.



Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!