Not sure how to put it right. While delving into the Laravel 4 classes to see how Facades work, I came across this:
Illuminate\Support\Facades\ Facades.php@ __callStatic public static function __callStatic($method, $args) { $instance = static::getFacadeRoot(); 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(array($instance, $method), $args); } }
Now, from what I can say, this method calls any given class method, references Facade, and passes arguments. I could be wrong, but this is my understanding so far.
The part that really bothers me is the switch.
Why are cases from 0 to 4 needed if the default case will work independently.
Even if case 0 makes sense, if there is no argument, why is there case 1-4, and not just continue case 10, for example. Is there a reasonable argument for this, or is it just a case of premature optimization?
source share