Section 11 - Overloaded syntax in the heavy duty PHP4 to establish mappings for external object models, just like Java and COM. PHP5 brings powerful object-oriented overload, allowing programmers to establish custom customizes Behavior to access attributes and call methods. The overload can be performed by several special methods of __get, __set, and and __call. When the Zend Engine tries to access a member and does not find it, PHP will call these methods. In Example 6.14 __ get and __set replace all the access to the attribute variable array. If necessary, you can implement any type you want filter. For example, the script can disable setting attribute values, with a certain prefix in the start of a certain type of value .__ call method Description How do you call an unfounded 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 the undefined method. LiSting 6.14 User-Level Overloading
class Overloader {private $ properties = array (); function __get ($ property_name) {if (isset ($ this-> 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 that does not exist attribute variables, activation __set () $ O-> Dynaprop = "Dynamic Content"; // invoke __get () activation __get () Print ($ O-> Dynaprop. "n"); // invoke __call () activation __call () $ O -> Dynamethod ("Leon", "Zeev");?>