I have compiled some of the PHP magic methods that will be used frequently in the development process, hoping to be helpful to everyone.
The Magic method is a predefined function in PHP that has a special purpose (which is triggered under certain conditions), which can be said to be a syntax conversion convention;
Magic methods are started by double underscores, such as __construct (), __destruct (), etc.;
Common Methods of Magic:
__construct,__destruct,__get,__set,__tostring
__construct:
Function: Initializes the object of the class
Called: Called when creating an object of a class
Parameters: Custom
__destruct:
Role: Destroying objects of a class
Call: When all references to the object of the class are not valid, the invoked condition is met, and the call of the PHP parser waits
Parameters: Object Name
Protection mechanisms
__call:
Role: Protects when a member method that does not exist is called
Called: Called when a member method that does not exist is called
Parameters: Function name, parameter class table (enumerated array)
__callstatic
Function: Protects when a static member method that does not exist is called
Call: Called when a static member method that does not exist is called
Parameters: Function name, parameter list (enum array)
__get:
Function: Protects when a nonexistent property is acquired
Called: Called when attempting to obtain a property that does not exist
Parameters: Variable Name
__set:
Function: Protects a non-existent attribute when assigned a value
Call: When attempting to assign a value to a property that does not exist
Parameters: variable name, value
__tostring:
Function: How a Class (object) should respond when treated as a string
Called: Called when an attempt is being taken to output a class object.
These are some of the common magic methods that I've compiled for PHP, and you can add some other methods by commenting.
Related articles:
PHP implementation of MySQL class with read and write separation function
PHP Strpos () function introduction and how to use a detailed explanation
Phpecho function Introduction and use method