长沙北大青鸟作者:科泰校区Leon Atkinson 翻译:Haohappy
<?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"); ?>
注:本文章为原创文章,版权归文章作者与超越PHP网站所有,未经本站同意,禁止任何商业转载。非盈利网站及个人网站转载请注明出处,谢谢合作!