Question

call_user_func_array()'s PHP manual's examples can only make me more confused with those foo and bar variables!

Anyway, please consider the _remap and ComplexFunction below:

class MyClass extends CI_Controller
{

    public function _remap($method, $params = array())
    {

        if (method_exists($this, $method))
        {
            return call_user_func_array(array($this, $method), $params);
        }

    }

    public function ComplexFunction($param1, $param2, $param3, $param4)
    {
        // process
        return 'done';
    }

}

Now will this piece of code work correctly?

$params = array(
                'param1' => '1',
                'param2' => '2',
                'param3' => '3',
                'param4' => '4'
               );

$myObject = new MyClass();

$output = call_user_func_array(array($myObject, 'ComplexFunction'), $params);

echo $output;
  1. Will the $output be done?
  2. Is that a reliable method to use in codeigniter's _remap() function?
Was it helpful?

Solution

This won't work, as the _remap() function is called by CI's core functions, and it's passed a separate argument for each segment in the matched route. You should never have to call the _remap() method yourself!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top