@
Leechael 我猜你这个MagicObject的意图是动态加方法和变量吧,@xinkiang的思路没错,也可以通过测试,可是那个MagicObject却没有实际用途啊
class MagicObject{
public $_mothods = array();
public $_vars = array();
public function __set($name,$value){
if(is_callable($value)) $this->_mothods[$name] = $value;
else $this->_vars[$name] = $value;
}
public function __get($name){
if(isset($this->_vars[$name]))return $this->_vars[$name];
}
public function __call($name,$args){
if(isset($this->_mothods[$name])){
array_unshift($args,$this);
return call_user_func_array($this->_mothods[$name],$args);
}
}
}