Access control for PHP interview questions. Access control for properties or methods is implemented by adding the public, protected, or private keywords. Class members defined by public can be accessed anywhere. access control over properties or methods is implemented by adding the public, protected, or private keywords. Class members defined by public can be accessed anywhere. class members defined by protected can be accessed by subclass and parent classes of their classes (of course, the class where the member is located can also be accessed), while the class members defined by private can only be accessed by the class where the member is located.
| The code is as follows: |
|
Class Foo
{
Private $ name = 'hdj ';
Public function getName (){
Return $ this-> name;
}
}
Class Bar extends Foo
{
Public $ name = 'deleka ';
}
$ Bar = new Bar;
Var_dump ($ bar-> name );
Var_dump ($ bar-> getName ()); |
Public, protected, or private. The class members defined by public can be accessed anywhere...