日期:2011-05-18 浏览次数:20516 次
<?PHP 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()<br>\n"); print("Arguments: "); print_r($args); return(TRUE); } } $o = new Overloader(); //invoke __set() 给一个不存在的属性变量赋值,激活__set() $o->dynaProp = "Dynamic Content"; //invoke __get() 激活__get() print($o->dynaProp . "<br>\n"); //invoke __call() 激活__call() $o->dynaMethod("Leon", "Zeev"); ?>