Home  >  Article  >  Backend Development  >  About PHP magic method description

About PHP magic method description

WBOY
WBOYOriginal
2016-08-08 09:33:111490browse

From php5 and later versions, classes can use magic methods. PHP stipulates that methods starting with two underscores (__) are reserved as magic methods, so it is recommended that function names do not start with __ unless it is to overload existing magic methods.

At present, all the magic methods in PHP include the following:

<span>__construct()
__destruct()
__call()
__callStatic()
__get()
__set()
__isset()
__unset()
__sleep()
__wakeup()
__toString()
__invoke()
__set_state()
__clone()
__debuglnfo()</span>

Why study these magic methods can enrich our knowledge. Programmers are like this. When you feel that you need a certain knowledge point, you will definitely study it.

It can be seen here that the names of magic methods all start with '__', which is two '_'

So we should not use '__' when defining class methods.

The above has introduced the description 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.

Statement:
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