PHP Magic function
Class person{private $name; Private $age; Private $sex; Public function __construct ($name, $age, $sex) {$this->name= $name; $this->age= $age; $this->sex= $sex; Public Function __get ($property) {if (Isset ($this-$property)) {return $this-$property; } else{return null; }} Public Function __set ($property, $value) {$this, $property = $value; }//When the private member $nm is measured outside the class using the Isset () function, the public function __isset ($property) {return isset ($this, $property) is called automatically; The Public Function __unset ($property) {unset ($this-$property) is automatically called when the unset () function is used outside the class to remove the private member; The __tostring () public function __tostring () {return ' Hello World ' is automatically called when the Echo object name is called directly outside the object.
"; }//When clone is called outside the object, the __clone () public function __clone () {$this->name= "I am Clone Object" is called automatically; }//When calling an object outside of the object's methods and parameters, instead of error, automatically call the __call function Public function __call ($function _name, $args) {print "You call the function: $function _name (parameter: "; Print_r ($args); Print ") does not exist!
\ n "; }//Serialize when serializing an object, automatically calls __sleep () public function __sleep () {}//Unserialize when the object is deserialized, automatically calls Wak EuP () Public function __wakeup () {}}function __autoload ($classname) {require_once ($classname. "). PHP ");