0

I wrote a small framework, but I am studying others. They are big, so I'm still trying to grasp their design.

When a user calls the controller or router, is call_user_func_array the typical way the page is "handed off" to the renderer?

I tend to see this type of thing which is what I did in mine. It looks like this is what it does in Codeigniter, but I am not sure.

if ((int)method_exists($controller, $action)) {
    call_user_func_array(array($dispatch,$action),$queryString);
} else {
    /* Error Generation Code Here */
}

I saw this in CodeIgniter:

// Execute the callback using the values in matches as its parameters.
$val = call_user_func_array($val, $matches);
johnny
  • 19,272
  • 52
  • 157
  • 259

1 Answers1

1

The call_user_func_array() function is used for when you don't know the function you are calling ahead of time. This is why most of the time, the parameters inside are variables.

If you know what function you want to call, always call it manually, otherwise, use this php in-built function.

You should look at the PHP documentation: http://php.net/manual/en/function.call-user-func-array.php

Also another stack overflow question sort of answers this: PHP call_user_func vs. just calling function

Community
  • 1
  • 1
nowy
  • 394
  • 2
  • 10
  • Then MVC frameworks using it correctly because they do now know which url the person will request? – johnny May 03 '15 at 23:01
  • 1
    yes, so `call_user_func_array(array($dispatch,$action),$queryString);` means: call the method `$action` using the parameters `$queryString` in the instantiated class `$dispatch` – nowy May 04 '15 at 00:33