我有以下代碼;什麼應該添加到裝飾類通過method_exists()
的檢查?在實際任務中,我無法更改調用method_exists()
的功能。
還有什麼想法如何欺騙'get_class_methods()'和'get_class_vars()'?修飾符和方法表達式
class real {
function __construct($arg1,$arg2)
{
}
function test()
{
echo "test output\n";
}
}
class decorator
{
protected $real;
function __construct()
{
eval('$this->real=new real('.implode(',',func_get_args()).');');
}
function __call($method,$args)
{
echo "called $method\n";
$ret=call_user_func_array(array($this->real, $method), $args);
return $ret;
}
public function __isset($name)
{
echo "isset $name\n";
}
}
//-----Can't change below
$r=new decorator(1,2);
if (!method_exists($r,'test')) {die ("method 'test' does not exist, Fail :(\n");}
echo $r->test();
任何想法? (我正在考慮通過eval()生成封裝類)
我做了eval()包裝,但希望更好的解決方案 –