Calling a function with explicit parameters vs. call_user_func_array()
<p>I saw a piece of code earlier this week (which, unfortunately, I am unable to retrieve) and I am curious about the way the author went about implementing the <code>__call()</code> magic method.  The code looked something like the following:</p>

<pre><code>class Sample
{
    protected function test()
    {
        var_dump(func_get_args());
    }
    public function __call($func, $args)
    {
        if(!method_exists($this, $func))
        {
            return null;
        }
        switch(count($args))
        {
            case 0:
                return $this-&gt;$func();
            case 1:
                return $this-&gt;$func($args[0]);
            case 2:
                return $this-&gt;$func($args[0], $args[1]);
            case 3:
                return $this-&gt;$func($args[0], $args[1], $args[2]);
            case 4:
                return $this-&gt;$func($args[0], $args[1], $args[2], $args[3]);
            case 5:
                return $this-&gt;$func($args[0], $args[1], $args[2], $args[3], $args[4]);
            default:
                return call_user_func_array($this-&gt;$func, $args);
        }
    }
}
</code></pre>

    

<pre><code>$obj = new Sample();
$obj-&gt;test("Hello World"); // Would be called via switch label 1
</code></pre>

<p>As you can see, the author could have just used <a href="http://php.net/call_user_func_array"><code>call_user_func_array()</code></a> and dropped the switch entirely, so that would lead to me to believe there was (hopefully) some intelligent reasoning behind this.</p>

<p>The only reason I could think of would be perhaps some overhead of the function call to <a href="http://php.net/call_user_func_array"><code>call_user_func_array()</code></a>, but that doesn't seem like a good enough reason to use a bunch of case statements.  Is there an angle here I don't seem to be getting?</p>
