Section 11 - Overloading
PHP4 already has overloading syntax to establish mapping to external object models, just like Java and COM. PHP5 brings powerful object-oriented overloading, allowing programmers to Build custom behaviors for accessing properties and calling methods.
Overloading can be done through several special methods __get, __set, and __call. PHP will call these when the Zend engine tries to access a member and cannot find it. Methods.
In Example 6.14, __get and __set replace all access to the attribute variable array. If necessary, you can implement any type of filtering you want. For example, the script can disable setting attribute values, at the beginning with A certain prefix or a value containing a certain type. The
__call method describes how you call an undefined method. When you call an undefined method, the method name and the parameters received by the method will be passed to the __call method, and PHP passes_ The value of _call is returned to undefined method.
Listing 6.14 User-level overloading
class Overloader
{
private $properties = array(); {
$this-> ;properties[$property_name] = $value;
;
http://www.bkjia.com/PHPjc/445271.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/445271.html
TechArticle
Section 11 - Overloading PHP4 already has overloading syntax to establish external object models Mapping, just like Java and COM. PHP5 brings powerful object-oriented overloading, allowing programmers to build...