PHP 5.4.17 替代“...运算符”

PHP 5.4.17 alternative for the "... operator"

我想知道是否有人知道 PHP 5.6.x 和更高 ... 运算符(或我认为它称为 splat 运算符)的替代方法。

我目前在我的 PHP 7 版本中做的是:

$this->callAction(
...explode('@', $this->routes["authControllers"][$this->routes["uri"][$uri]])
);

callAction() 函数需要 2 个参数 callAction($controller, $action) 但现在我需要将代码降级到 PHP 5.4.17.

我认为等效的 PHP5 代码是 call_user_func_array(array($this,'callAction'),(explode('@', $this->routes["authControllers"][$this->routes["uri"][$uri]])));

编辑:但是如果 callAction 总是恰好接受 2 个参数,您可以这样做

$args=explode('@',$this->routes["authControllers"][$this->routes["uri"][$uri]]));
$this->callAction($args[0],$args[1]);

但如果是这样的话,我想知道为什么 php7 代码会与 ... 打扰,我认为那是为了可变数量的参数? (例如 call_user_func_array 是为了。有关采用可变数量参数的函数的示例,请参阅 var_dump

尽管 splat 运算符 ... 类似于 call_user_func_array():

call_user_func_array(array($this,'callAction'),
                     explode('@', $this->routes["authControllers"][$this->routes["uri"][$uri]]));

我认为传递所需参数更有意义:

list($controller, $action) = explode('@', $this->routes["authControllers"][$this->routes["uri"][$uri]]);
$this->callAction($controller, $action);