They can be used in the class attributes and methods (class attributes and methods are collectively called class members) to modify the access permissions of class members. PHP has three access modifiers:
Public (public, default)
Protected (protected)
Private)
They can be used in the class attributes and methods (class attributes and methods are collectively called class members) to modify the access permissions of class members.
Public (public, default)
In PHP5, if the class does not specify the access modifier of the member, the default access permission is public.
/*
The following two methods declare that the access permission works the same
*/
Function say (){};
Publilc function say (){};
When a class member is declared as a public access modifier, the member can be accessed and operated by external code.
Private)
A private member is visible to all members in the class and has no access restrictions. Access to the outside of the class is not allowed.
Protected (protected)
Protected is a little complicated. it is declared as a member of protected and can only be accessed by subclass of this class.
Access permission list:
Access permission |
Public |
Protected |
Private |
All |
★ |
|
|
Subclass |
★ |
★ |
|
Class |
★ |
★ |
★ |