PHP magic method summary

Magic method is a unique feature of PHP object-oriented. They are triggered under certain circumstances, all start with a double underscore. Here is a summary and share with you


1.__construct, __destruct
__constuct is called when the object is constructed;
__destruct is called when the object is explicitly destroyed or the script ends ; 2


.__ GET, __ SET
the __set when given inaccessible or property assignment does not exist is called
__get read invoked is inaccessible or absence of a property


. 3 .__ isset, __ the unset
the __isset call inaccessible or nonexistent property isset () or Called when empty()
__unset is called when an inaccessible or non-existent attribute is unset


4.
__call , __callStatic __call is called when an inaccessible or non-existent method is called
__callStatic is called when an inaccessible or non-existent static method is called


5.
__sleep, __wakeup __sleep is called when serialize is used, and is useful when you don’t need to save all the data of a large object.
__wakeup is called when unserialize is used and can be used to initialize some objects.


6. __clone
is used when cloning objects. Called to adjust the cloning behavior of the object


7.__toString
It is called when a class is converted into a string.


8.__invoke is called
when the object is called as a function.


9.__set_state is called
when var_export() is called to export the class. This static method is called. Use the return value of __set_state as the return value of var_export.


10. __debuginfo is
called when var_dump() is called to print the object (when you don't want to print all the attributes), it is applicable to PHP5.6 version
 
For more technical questions, please search Qianfeng PHP, be your true self, and use your conscience to educate

Guess you like

Origin blog.csdn.net/chengshaolei2012/article/details/72638543