Home > Backend Development > PHP Tutorial > Summary table of the uses and functions of commonly used magic methods in PHP

Summary table of the uses and functions of commonly used magic methods in PHP

little bottle
Release: 2023-04-06 12:02:01
Original
2271 people have browsed it

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:

##__isset There is a parameter __isset (the attribute name to be judged) Used to detect whether the private attribute exists__unsetThere is a parameter __unset (the deleted attribute name) Used to delete private attributes##__call
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

##Related tutorials:

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template