2017-06-21 111 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

感謝您的回覆 –