Any PHP developer needs to master 6 keywords when using object-oriented to build WEB applications. They are:
1.Private
2.Public
3.Protected
4.Static
5.Final
6.Abstract
For the first three keywords, their access relationship within the class is as follows:
Protected
Protected’s access level is second only to Private. Properties (variables) or methods defined as Protected can be accessed not only in this class, but also in subclasses of this class. It can also be accessed in the class, which is not possible with Private attributes.
Public
Public has the greatest access rights. Properties (variables) or methods defined as Public can be accessed anywhere in the program and at any time.
static
When we declare an attribute (variable) as static in a class, then the value of the attribute is visible in all its objects and is a Shared variables, therefore, static attribute values depend on the class rather than the object. Static properties cannot be accessed through objects, but can be accessed directly using the class name plus the :: symbol.
Similarly, static methods also have object sharing characteristics, but you need to pay attention to the following two points:
1. Access static methods directly by adding :: to the class name
2. The $this keyword cannot be used in static methods
Final
If an attribute (variable) is modified by Final, then the attribute (variable) value cannot be changed. If it is a function, the function cannot be overwritten or rewritten.
Abstract
A class defined as Abstract cannot be instantiated. Any class, if at least one method in it is declared as Abstract, then this class must be declared as Abstract. A method defined as Abstract only declares its calling method (parameters) and cannot define its specific function implementation.