PHP 5.4.17 alternative for the “… operator”

前端 未结 2 1350
耶瑟儿~
耶瑟儿~ 2021-01-25 09:55

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).

What i\'m currently do

2条回答
  •  终归单人心
    2021-01-25 10:53

    i think the equivalent PHP5 code would be call_user_func_array(array($this,'callAction'),(explode('@', $this->routes["authControllers"][$this->routes["uri"][$uri]])));

    edit: but if the callAction always takes exactly 2 arguments, you could just do

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

    but if thats the case, idk why the php7 code bothers with the ... at all, i thought that was for variable number of arguments? (like call_user_func_array is for. for an example of a function that takes a variable number of arguments, see var_dump)

提交回复
热议问题