PHP 5.4.17替代"...运算符" [英] PHP 5.4.17 alternative for the "... operator"
本文介绍了PHP 5.4.17替代"...运算符"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有人会知道PHP 5.6.x和更高版本的...
运算符(或我相信它称为splat运算符)的替代方法.
I was wondering if someone may know an alternative to the PHP 5.6.x and higher ...
operator (or splat operator I believe its called).
我当前在PHP 7版本中所做的是:
What i'm currently doing in my PHP 7 version is:
$this->callAction(
...explode('@', $this->routes["authControllers"][$this->routes["uri"][$uri]])
);
callAction()
函数具有2个参数callAction($controller, $action)
,但是现在我需要将代码降级为PHP 5.4.17.
The callAction()
function takes 2 parameters callAction($controller, $action)
but now I need to downgrade the code to PHP 5.4.17.
推荐答案
尽管splat运算符...
与call_user_func_array()
相似:
Though the splat operator ...
is similar to call_user_func_array()
:
call_user_func_array(array($this,'callAction'),
explode('@', $this->routes["authControllers"][$this->routes["uri"][$uri]]));
我认为传递必需的参数会更有意义:
I think it would make more sense to pass the required arguments:
list($controller, $action) = explode('@', $this->routes["authControllers"][$this->routes["uri"][$uri]]);
$this->callAction($controller, $action);
这篇关于PHP 5.4.17替代"...运算符"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文