Dynamic Function Call PHP

為{幸葍}努か 提交于 2019-12-12 06:13:48

问题


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();

Like this:

$objects = $this->module->'GetObjects'.ucfirst($key).'Array'();

回答1:


Maybe

$objects = $this->module->{'GetObjects'.ucfirst($key).'Array'}();

or

$objects = call_user_func(array($this->module, 'GetObjects'.ucfirst($key).'Array'));


来源:https://stackoverflow.com/questions/4218123/dynamic-function-call-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!