1

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?
Mohammad Naji
  • 5,372
  • 10
  • 54
  • 79
  • 1
    Did you tried it? Why are you instantiating the controller like that? – Damien Pirsy Feb 18 '12 at 13:20
  • In fact I was looking for a general way. This is not the way that I use my controller. There are also many other methods in my controller. I should use the `_remap` function because the `search()` method should has many optional parameters that are passed in user defined order. – Mohammad Naji Feb 18 '12 at 17:16

1 Answers1

2

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!

landons
  • 9,502
  • 3
  • 33
  • 46