Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 正确使用call\u user\u func\u数组_Php_Callback_Smarty_Argument Passing_Lithium - Fatal编程技术网

Php 正确使用call\u user\u func\u数组

Php 正确使用call\u user\u func\u数组,php,callback,smarty,argument-passing,lithium,Php,Callback,Smarty,Argument Passing,Lithium,我正在尝试用smarty扩展Limition PHP,除了我的smarty插件允许访问Limition helpers外,其他一切都正常工作 我的smarty功能旨在成为锂助手的“通俗易懂”功能。我正在努力解决的部分是动态地将helpers参数添加到我的回调中 简化代码 $params = array('Google', 'http://www.google.com'); $helper = function($args){ return $this->html->li

我正在尝试用smarty扩展Limition PHP,除了我的smarty插件允许访问Limition helpers外,其他一切都正常工作

我的smarty功能旨在成为锂助手的“通俗易懂”功能。我正在努力解决的部分是动态地将helpers参数添加到我的回调中

简化代码

$params = array('Google', 'http://www.google.com');

$helper = function($args){  
    return $this->html->link($args);
};

return call_user_func_array($helper, $params);
这将导致

一些进一步的测试表明,上面只将$params数组中的第一项传递给回调函数。。。奇怪。所以我把它包装在自己的数组中。拿着那个,我无法解释的东西

return call_user_func_array($helper, array($params));
这会产生一个我不会遇到的错误,但是看起来助手被传递了一个数组,而不是作为单个参数从数组中转换过来的参数

错误片段 '未找到URL
(0=>'谷歌',1=>'的参数匹配项'http://www.google.com“,“控制器”=>“页面”,“操作”=>“索引”)

所以我推断我误用了call\u user\u func\u数组方法

我不相信这是实现我目标的唯一解决方案,如果你能想出一个更好的方法,在任何时候动态地传递一个函数,任何数量的参数,我将不胜感激

请注意:$this->
html
->
link
是解释我的问题的一种简化方法,该对象的
html
link
部分实际上会动态更改,因此需要完全动态的函数参数


$helper
仅用一个参数声明,并且只有一个参数被传输到
$this->html->link

为什么不使用
调用用户函数数组(数组($this->html,'link')、数组($params))为什么不直接编码

return $helper($params);
我认为不需要调用用户函数数组()


或者请澄清你为什么要这样做,因为对我来说这是可行的。

问题是$this->html->link需要传递这样的信息$this->html->link('Google','),而不是$this->html->link(array('Google',')),所以只传递$params是不够的。好吧,现在我明白了:)然后我的答案就过时了。无论如何,谢谢,@kirloid的回答让我找到了我需要去的地方