4

Say$this->varname等于is_callable()返回 true 的字符串。要调用它,我必须这样做,$temp = $this->varname; $temp();或者......有没有另一种方法可以调用它而不必创建两条线?

这样做的问题$temp = $this->varname()是,它会尝试调用类中名为 varname() 的方法——它不会调用 $this->varname 处的函数。

谢谢!

4

2 回答 2

1

另一种选择是call_user_func

call_user_func($this->varname);
于 2013-04-08T21:06:10.027 回答
1

您必须这样做或使用call_user_func(_array). 或者正如 Anthony 在内部 ( http://www.mail-archive.com/internals@lists.php.net/msg64647.html ) 上向我建议的那样,您可以这样做${'_'.!$_=$this->varname}();

已经存在对 PHP 的拉取请求,正在内部讨论:https ://github.com/php/php-src/pull/301 (和 rfc https://wiki.php.net/rfc/fcallfcall )

于 2013-04-08T21:09:12.617 回答