2017-06-21 110 views
0

我想知道是否有人可能知道替代PHP 5.6.x和更高版本的运算符(或者我认为它被称为splat运算符)的...PHP 5.4.17“...运算符”的替代方案

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

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

callAction()功能需要两个参数callAction($controller, $action)但现在我需要的代码降级到PHP 5.4.17。

+1

PHP 5.4将近两年没有支持,因此运行危险并不安全。也就是说,旧的方法是使用http://php.net/func_get_args代替。 – ceejayoz

+0

谢谢我看看func_get_args。 是的,我知道它已经退出了一段时间的支持,但我的老师并没有更新他的本地服务器:/ –

+1

要么爆炸到一个数组,并通过'0'和'1'或使用'call_user_func_array ()'。 – AbraCadaver

回答

0

虽然图示操作...类似于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); 
+0

感谢您的回复 –

0

我觉得相当的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]); 

,但如果多数民众赞成的情况下,IDK的为什么PHP7代码困扰...在所有,我认为这是为可变数目的参数? (如call_user_func_array是对于采用可变数量的参数的函数的一个例子,见var_dump

+0

感谢您的回复 –