There are three types of access modifiers in PHP , namely:
Public (common, default)
Protected (Protected)
Private (privately)
They can be used, respectively, on the properties and methods of a class (the properties and methods of a class are collectively referred to as members of a class), and are used to decorate the access rights of class members.
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 to the same effect
*/
function say () {};
PUBLILC function Say () {};
When a member of a class is declared as a public access modifier, that member can be accessed and manipulated by external code.
Private (privately)
A member that is defined as private and is visible to all members of the class without access restrictions. Access is not allowed outside the class.
Protected (Protected)
Protected is slightly more complex and is declared to be a member of the protected, allowing access only to subclasses of that class.
Access Status Table :
access |
public |
protected |
private |
All |
★ |
|
|
Sub-class |
★ |
★ |
|
In-Class |
★ |
★ |
★ |
There are three access modifiers in PHP that are public by default