This article mainly talks about the use and function of common magic methods in PHP. Friends who are interested can save it in case they need it. I hope it can help you.
What are PHP magic methods?
When defining a class, methods starting with two underscore characters (__) are all magic methods, and the method names are all pre-defined by PHP, each of which has magic functions.
So when we define a method ourselves, we do not recommend starting with two underscore characters, as this will confuse it with PHP's magic method.
The following table is a summary of the uses and effects of commonly used magic methods:
Magic method |
Calling method |
## Function |
__set |
There are two parameters __set (attribute name, attribute value) |
Modify private attributes |
__get |
There is a parameter __get(attribute Name) |
View private properties |
## has two parameters __call(function name, function value) |
If there is no such function in the class, this function will be executed |
PHP video tutorial
The above is the detailed content of Summary table of the uses and functions of commonly used magic methods in PHP. For more information, please follow other related articles on the PHP Chinese website!