| 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 ");?>