Home > Backend Development > PHP Tutorial > php如何实现动态传参数?

php如何实现动态传参数?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:54:58
Original
1840 people have browsed it

php怎么实现动态传参数???

本帖最后由 ic2y__ 于 2014-04-17 17:21:01 编辑 先贴代码,代码精简了。
<br /><?php <br /><br />class Cache{<br />	public function get()<br />	{<br />			$invoker			= debug_backtrace();<br />			$invoker_class		= $invoker[1]["class"];<br />			$invoker_function	= $invoker[1]["function"]."_redirect";<br /><br />			$argus				= func_get_args();<br />		        $invoker_class		= str_replace("Action","", $invoker_class);<br />		<br />			D($invoker_class)->$invoker_function($argus);<br />	}<br />}<br />?><br />
Copy after login

描述:
程序是在ThinkPHP开发,目的是把Cache的get方法接收的参数转发到指定的方法上,
最后一行:其中D方法是ThinkPHP自带的方法用的是单例模式。如果不加参数$argus是可以正常调用的。

问题:
现在想传递参数,比如get("name","age"),完整的传递到 D($invoker_class)->$invoker_function(“name”,"age")上,有什么办法。

call_user_func 看起来像是可以,不过看不出来怎么用。

求解。
------解决方案--------------------
call_user_func_array(array(D($invoker_class), $invoker_function), $argus);
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template