There are three types of access modifiers in PHP, respectively:
public (common, default)
protected (Protected)
Private (private)
They can be used to modify the access rights of class members, respectively, on the properties and methods of the class (the class's properties and methods are collectively referred to as members of the class).
public (common, default)
in PHP5 if the class does not have an access modifier for the specified member, the default is public access.
/*
The following two methods declare access permissions the same
*/
function Say () {};
publilc function Say () {};
when a member of a class is declared to be a public access modifier, that member can be accessed and manipulated by external code.
Private (private)
are defined as private members and are visible to all members within a class, without access restrictions. Access is not allowed outside of the class.
protected (Protected)
protected is slightly more complex and is declared as a member of the protected, allowing access only to subclasses of that class.
access Rights table :
access rights td> |
public |
protected |
private |
|
★ |
|
|
subclass |
★ |
★ |
align= "center" > |
class |
★ |
★ /td> |
★ |