使用动态方法(Using dynamic methods)
为什么我的动态方法usersMethod不返回任何结果? 页面始终为空。
<?php class SampleClass { public function __call($name, $args) { $m = $this->methods(); eval($m['usersMethod']); } public function methods() { $methods = array( 'usersMethod'=>'$a=2; return $a;', 'membersMethod'=>'$a=1; return $a;' ); return $methods; } } $sample = new SampleClass(); echo $sample->usersMethod(); ?>Why does my dynamic method usersMethod not return any result? The page is always empty.
<?php class SampleClass { public function __call($name, $args) { $m = $this->methods(); eval($m['usersMethod']); } public function methods() { $methods = array( 'usersMethod'=>'$a=2; return $a;', 'membersMethod'=>'$a=1; return $a;' ); return $methods; } } $sample = new SampleClass(); echo $sample->usersMethod(); ?>最满意答案
您需要返回eval的值:
return eval($m['usersMethod']);(见这个答案 )
You need to return the value of eval:
return eval($m['usersMethod']);(See this answer)
更多推荐
发布评论