<?php class Magic{ private $name; /** * Constructor called automatically when the class is instantiated, the general operations for initialization * / Public function the __construct () { echo "automatically call the __construct () method \ n-" ; } /** * Destructor method, an object is destroyed when the call is automatically * / Public function __destruct () { echo "I object to call \ n is destroyed" ; } /** * Cloning method, when the object to be cloned, will automatically call * / Public function a __clone () { echo "is called when the object is cloned \ n-" ; } /** * Property acquisition method, when an object to be called a protected or non-existent property, __ get method will automatically be called, and incoming call attribute name * / Public function __get ( $ Key ) { echo "you call the property does not exist or do not have permission to access \ the n-" ; } /** * Attribute setting method, when the object to be protected or set up a non-existent property, __ set will be executed, and to pass * Attribute names and attribute values set, note set here so that the object itself has not changed, unless change occurs in the operating method __set * / Public function __set ( $ Key , $ value ) { echo "you attribute set does not exist or do not have permission to access \ the n-" ; } /** * When used isset determines whether an object has this property and this property is absent or is protected automatically executed, the name attribute is determined and passed * * / Public function The __isset ( $ Key ) { echo "attribute { $ Key } or a protected \ n does not exist" ; } /** * When deleting an object with the protection of property or does not exist unset attributes, it is automatically executed * * / Public function __unset ( $ Key ) { echo "attribute you want to delete { $ Key } or protected \ n does not exist" ; } /** * When an object to be protected or absence of a call, it will automatically execute and pass two parameters $ method is the method you, parameter array $ arguments for the method of * * / Public function __call ( $ Method, , $ params ) { echo "{method that you are calling $ Method, } does not exist \ the n-" ; } /** * When you call a static method of a class which is protected or does not exist, it will automatically execute and pass two parameters for the method $ method, $ arguments for the parameter array method * * / Public static function __callStatic ( $ Method, , $ params ) { echo "{static method that you are calling $ Method, } the n-does not exist \" ; } /** * For a class should be treated as a string how to respond * / Public function the __toString () { return "that an object is not directly output \ n-" ; } /** * When trying to call an object to invoke a function * / Public function __invoke ( $ K ) { echo "I am an object is not a function of { $ K } \ n-" ; } /** * Object is called before serialization * * / Public function __sleep () { echo "is called before the object is serialized \ n-" ; } /** * Object is called before deserialized * * / Public function the __wakeup () { echo "is called before the object deserialized \ n-" ; } } $magic = new Magic(); $magic_clone = clone($magic); echo $magic->name; $magic->name = "hahaha"; isset($magic->sex); unset($magic->sex); $magic->setName(); Magic::setName(); echo $magic; $magic("mayuan"); $magic_se = serialize($magic); unserialize($magic_se);
Reproduced in: https: //www.cnblogs.com/itsuibi/p/11051936.html