使用动态方法(Using dynamic methods)

编程入门 行业动态 更新时间:2024-10-28 16:30:20
使用动态方法(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)

更多推荐

本文发布于:2023-04-28 07:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1331392.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   动态   methods   dynamic

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!