Home > Article > Backend Development > PHP Magic Method Definition Magic Quick Fight Poker Magic Deadly Magic
There are some special functions and methods in PHP. The special thing about these functions and methods compared with ordinary methods is that user code usually does not actively call them, but will be automatically called by PHP at specific times.
In PHP, methods starting with "__" are usually regarded as magic methods. The PHP manual recommends that custom methods do not start with __.
php’s magic methods are:
__construct(), __destruct(), __call(), __callStatic(), __get(), __set(), __isset(), __unset(), __sleep(), __wakeup(), __toString(), __invoke(), __set_state(), __clone() and __debugInfo()
__construct(), the construction method, students who are familiar with object-oriented should be familiar with it, allocate space for the object when new object is created.
__destruct(), the constructor method corresponds to the destructor method. The destructor method allows you to perform some operations or complete some functions before destroying a class, such as closing files, releasing result sets, etc. Destructor cannot take parameters
The above introduces the definition of PHP magic methods, including the content of PHP magic methods. I hope it will be helpful to friends who are interested in PHP tutorials.