Section 11 - Overload - Classes and Objects in PHP5 [11]

zhaozj2021-02-16  50

Section 11 - Overload - Classes and Objects in PHP5 [11]

Author: Leon Atkinson translation: Haohappy Source: Beyond the PHP / * ------------------------------------ ------------------------------------------ | = This article is HaohappY << CORE PHP Programming >> | = Classes and Objects Chapter Note | = Translate Main Personal Experience | = To avoid unnecessary troubles, please do not reprint, thank you | = Welcome criticism, hope and all PHP enthusiasts progress together! ----------------------------------------- ---------------------------------- * / 11th - Reserved PHP4 With overloaded grammar to establish mapping for external object models, just like Java and COM. PHP5 brings powerful object-oriented overload, allowing programmers to establish custom behavior to access properties and call methods. Overload There can be several special methods of __get, __set, and and __call. When the Zend Engine tries to access a member, PHP will call these methods. In Example 6.14, __ get and __set replace all the array of attribute variables Visit. If necessary, you can implement any type you want filter. For example, the script can disable setting attribute values, with a certain prefix with a certain prefix or contain a certain type .__ call method Description How do you call unfained Method. When you call an undefined method, the parameters received by the method name and method will pass to the __call method, PHP delivery __call, return to undefined methods. LISTING 6.14 User-Level Overloading Properties [$ proty_name])) {return ($ this-> Properties [$ proty_name]);} else {return (null) ;}} function __set ($ proty_name, $ value) {$ this-> Properties [$ proty_nam e] = $ value;} function __call ($ function_name, $ args) {print ("Invoking $ function_name ()
); Print (" arguments: "); Print_R ($ args); return (True) }}} $ o = new overloader (); // invoke __set () gives an unsavailable attribute variable assignment, activation __set () $ O-> Dynaprop = "Dynamic Content"; // invoke __get () activation _ _Get () Print ($ O-> Dynaprop. "
N"); // invoke __call () activation __call () $ O-> Dynamethod ("Leon", "Zeev");?>>

转载请注明原文地址:https://www.9cbs.com/read-21564.html

New Post(0)