Call_user_func_array vs $ controller & # 8594; $ method ($ params)?

I use this in my code:

 call_user_func_array ( array ($controller, $method ), $this->params );

but I found out that the code below does the same:

 $controller->$method($this->params);

Is there a difference between the two versions?

thank

Adam Ramadhan

+5
source share
3 answers

They do not match.

If $method- showAction, and $this->params- array(2, 'some-slug'), then the first call will be equivalent:

$controller->showAction(2, 'some-slug');

While the second will be:

$controller->showAction(array(2, 'some-slug'));

Which one you want to use depends on how your system works (for example, your controllers). I personally will probably go with the first one.

+5
source

. , $controller->$nonexistant() . call_user_func_array E_WARNING, $method .

. $ $, :

call_user_func_array ( $controller->$method, $this->params );
+4

They do the same, but the second form is shorter, clearer and faster. I prefer it.

0
source

All Articles