Defined:
The method that begins with the two line "__" in the PHP class is called the Magic method.
Classification:
For example: Construction method: __construct; destructor: __destruct; dynamic reload: __set (), __get (), __call (), __callstatic (), Clone of object: __clone ()
Application Scenarios:
1. When the program attempts to modify a non-existent or invisible class property, the PHP engine will call the __set () method, if the method is defined in the class. __set () is defined in the following format:
function __set ($name, $value) {
Implementation Details
}
Where $name is a dynamically created variable name, $value is the value of the variable.
2. When the program attempts to read a non-existent or invisible class attribute, the PHP engine will call the __get () method, if the method is defined in the class. __get () is defined in the following format:
function __get ($name) {
Implementation Details
}
Where $name are dynamically created variable names.
3. When the program tries to invoke a non-existent or invisible class method, the PHP engine will call the __call () method, if the method is defined in the class. The __call () method is defined in the following format:
function __call ($name, $args) {
Implementation Details
}
Where $name is the dynamically created method name, $args is the parameter of the method, in the form of an array.
4, starting from PHP5.3.0, you can use __callstatic () to dynamically create static methods. __callstatic () is defined in the following format:
function __callstatic ($name, $args) {
Implementation Details
}
Where $name is the dynamically created method name, $args is the parameter of the method, in the form of an array.
5. Once the __clone () method is defined, the class is automatically called when it is copied, so that we can re-open the memory to the reference property in the __clone () method. The __clone () definition format is as follows:
function __clone () {
Implementation Details
}
The above describes the PHP magic method in the PHP class magic method, including the PHP magic method of the content, I hope the PHP tutorial interested in a friend helpful.