动态函数调用PHP [英] Dynamic Function Call PHP
本文介绍了动态函数调用PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个非常具体的问题:以下代码可能在一行中?或者有更好的做法吗?
I have a very specific question: is the following code possible in one line? Or is there a beter way to do the same?
$key = rand(1,100);
$temp = 'GetObjects'.ucfirst($key).'Array';
$objects = $this->module->$temp();
像这样:
$objects = $this->module->'GetObjects'.ucfirst($key).'Array'();
推荐答案
也许
$objects = $this->module->{'GetObjects'.ucfirst($key).'Array'}();
或
$objects = call_user_func(array($this->module, 'GetObjects'.ucfirst($key).'Array'));
这篇关于动态函数调用PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文