PHP magic functions

Source: Internet
Author: User
PHP magic functions

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 isset () function is used outside the class to determine the private member $ nm, automatically call public function _ isset ($ property) {return isset ($ this-> $ property);} // When unset () is used outside the class () public function _ unset ($ property) {unset ($ this-> $ property );} // automatically call _ toString () public function _ toString () {return "hello world" when the echo object name is directly called outside the object "."
";} // Automatically call _ clone () public function _ clone () when calling clone outside the object () {$ this-> name = "I am clone object";} // when no methods or parameters exist in the object's external call, an error is returned, automatically call the _ call function public function _ call ($ function_name, $ args) {print "Your called function: $ function_name (parameter:"; print_r ($ args ); print ") does not exist!
\ N ";}// serialize automatically calls _ sleep () public function _ sleep () When serializing the object () {}// when the object is deserialized, the unserialize automatically calls the wakeup () public function _ wakeup () {}} function _ autoload ($ classname) {require_once ($ classname. ". php ");}

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.