Let's go to the discussion: These days ago I took a look at the source code of a ZendFramework2 class. There was an implementation of the __call
magic method. In this method there was something that caught my attention: The use of call_user_func_array
was restricted only when the method attempted to call had more than 4 arguments. There was also a comment in English, which I forgot which it is, which explains why.
To confirm that this was not my fault (nor from ZendFramework), I went to look at the source code of Laravel4
and I came across the same thing (but without the comment specifying why).
See the snippet of code:
public static function __callStatic($method, $args)
{
$instance = static::getFacadeRoot();
if (! $instance) {
throw new RuntimeException('A facade root has not been set.');
}
switch (count($args)) {
case 0:
return $instance->$method();
case 1:
return $instance->$method($args[0]);
case 2:
return $instance->$method($args[0], $args[1]);
case 3:
return $instance->$method($args[0], $args[1], $args[2]);
case 4:
return $instance->$method($args[0], $args[1], $args[2], $args[3]);
default:
return call_user_func_array([$instance, $method], $args);
}
}
Note that Laravel
only considers using call_user_func_array
if the call of __callStatic
has a passing of 5 or more arguments.
Interesting of this is that personally I would consider this useless typing of code, since call_user_func_array
would make the call of a method or function much more dynamic, but two known libraries did just the way that seemed more complex.
So, I'd like to know why.
Is there a problem in performative loss (at a meaningful level) that would induce frameworks to do this?
Is there any hint of PHP itself that indicates this?
Note : Who wants to check the code, see here: link