Section 11th -- overload -- ClassesandObjectsinPHP511

Source: Internet
Author: User
| Read this article for Haohappy | notes in the ClassesandObjects chapter | main Translation + personal experience | to avoid unnecessary troubles, please do not repost it. thank you | welcome to correct your criticism, hope to make progress together with all PHP enthusiasts! + --------------------------------------- SyntaxH

| = This article is Haohappy read < > | = Notes in the middle Classes and Objects chapter | = Translation + personal experience | = do not repost to avoid unnecessary troubles, thank you | = Welcome to criticize and correct, hope to make progress together with all PHP enthusiasts! + Runtime + */section 11th -- the overloaded PHP 4 syntax is used to create a ING of the external object model, just like Java and COM. PHP5 brings powerful object-oriented overloading, allowing programmers to establish custom behaviors to access attributes and call methods. you can use several special methods such as _ get, _ set, and _ call for overloading. PHP will call these methods when the Zend Engine tries to access a member that is not found. in Example 6.14, __get and _ set replace all accesses to the attribute variable array. if necessary, you can implement any type of filter you want. for example, a script can disable attribute values and use a certain prefix or contain certain types of values at the beginning. the _ call method describes how to call an undefined method. when you call an undefined method, the method name and parameters received by the method will be passed to the _ call method, and the value of _ call passed by PHP will be returned to the undefined method. listing 6.14 User-level overloading Properties [$ property_name]) {return ($ this-> properties [$ property_name]);} else {return (NULL) ;}} function _ set ($ property_name, $ value) {$ this-> properties [$ property_name] = $ value;} function _ call ($ function_name, $ args) {print ("Invoking $ function_name ()

N "); print (" Arguments: "); print_r ($ args); return (TRUE) ;}$ o = new Overloader (); // invoke _ set () assigns a value to a non-existent attribute variable and activates _ set () $ o-> dynaProp = "Dynamic Content "; // invoke _ get () activate _ get () print ($ o-> dynaProp."
N "); // invoke _ call () activation _ call () $ o-> dynaMethod (" Leon "," Zeev ");?>

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: 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.