I found this weird switch statement in Laravel 5 core:
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);
Is there any reason why they possibly decided to build such a thing instead of just using this?
return call_user_func_array([$instance, $method], $args);
Any benefits?
IMHO the programmer avoided to call_user_func_array() for a reasonable amount of typical calls to $instance->method(). Of course it is faster to call the method directly instead of using call_user_func_array(). The code was written with love :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With