PHP Magic Method Summary

Source: Internet
Author: User

The Magic method is a unique feature of PHP object-oriented. They are triggered under certain circumstances, all starting with a double underscore, you can interpret them as hooks, and the pattern method makes it easy to implement PHP object-oriented overloading (overloading, which dynamically creates class properties and methods). Many of the magic methods are still paired, and the following list shows all the schema methods in PHP currently.


1.__construct,__destruct

__constuct is called when the object is built;

__destruct explicitly destroys the object or is called at the end of the script;


2.__get,__set

__set called when an attribute assignment is not accessible or does not exist

__get is called when read is not accessible or there is no property


3.__isset,__unset

__isset called when isset () or empty () is called on an inaccessible or nonexistent property

__unset called when an unreachable or nonexistent property is unset


4.__call,__callstatic

Called when __call calls a method that is not accessible or does not exist

Called when __callstatic calls a static method that is not accessible or does not exist


5.__sleep,__wakeup

__sleep is called when using serialize, which is useful when you don't need to save all the data for a large object

__wakeup is called when using unserialize, and can be used for initialization of objects


6.__clone

Called when the object clone is being used to adjust the cloning behavior of the object


7.__tostring

Called when a class is converted to a string


8.__invoke

Called when an object is called in a functional manner


9.__set_state

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


10.__debuginfo

Called when a var_dump () print object is called (when you do not want to print all properties) for the PHP5.6 version


PHP Magic Method Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.