PHP Magic function

Source: Internet
Author: User
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 ");
  • Related Article

    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.