Six keywords that PHP developers must master
- 2020-03-30 02:39:04
There are six key words any PHP developer needs to master when building an object-oriented WEB application. They are:
1. The Private
3. The Protected
4. The Static
5. The Final
6. The Abstract
For the first three keywords, they access the relationship within the class as follows:
< img border = 0 id = theimg onclick = window. The open this. (SRC) SRC = "/ / files.jb51.net/file_images/article/201404/2014414103324312.gif? 2014314103338 ">
As shown in the figure above, Private is the core of access control, so properties (variables) or methods defined as Private in a class can only be accessed within the class, no instance (object) or subclass of the class can be accessed, and you cannot access them directly by the class name.
Protected has a level of access next to Private, and a property (variable) or method defined as Protected can be accessed not only in this class, but also in subclasses of this class, which cannot be accessed by the Private property.
Public has the maximum access, and properties (variables) or methods defined as Public can be accessed from anywhere in the program at any time.
When we declare a property (variable) as static in a class, the value of the property is visible in all its objects and is a Shared variable, so the value of the static property depends on the class rather than the object. Static properties cannot be accessed by objects, but directly by the class name plus the :: symbol.
Also, static methods have an object sharing feature, but there are two things to note:
1. Access static methods directly by adding :: to the class name
2. The $this keyword cannot be used in static methods
If a property (variable) is modified with Final, the value of that property (variable) cannot be changed, and if it is a function, the function cannot be overwritten or overwritten.