时间:2021-07-01 10:21:17 帮助过:9人阅读
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() 给一个不存在的属性变量赋值,激活__set()
$o->dynaProp = "Dynamic Content";
//invoke __get() 激活__get()
print($o->dynaProp . "n");
//invoke __call() 激活__call()
$o->dynaMethod("Leon", "Zeev");
?>