Ti posto un estratto del metodo dispatchMethod() della classe base Object di CakePHP:
Codice PHP:
/**
* Calls a method on this object with the given parameters. Provides an OO wrapper
* for call_user_func_array, and improves performance by using straight method calls
* in most cases.
*
* @param string $method Name of the method to call
* @param array $params Parameter list to use when calling $method
* @return mixed Returns the result of the method call
* @access public
*/
function dispatchMethod($method, $params = array()) {
switch (count($params)) {
case 0:
return $this->{$method}();
case 1:
return $this->{$method}($params[0]);
case 2:
return $this->{$method}($params[0], $params[1]);
case 3:
return $this->{$method}($params[0], $params[1], $params[2]);
case 4:
return $this->{$method}($params[0], $params[1], $params[2], $params[3]);
case 5:
return $this->{$method}($params[0], $params[1], $params[2], $params[3], $params[4]);
default:
return call_user_func_array(array(&$this, $method), $params);
break;
}
}
Ovviamente non puoi usare call_user_func_array() per istanziare una nuova classe, ma penso tu possa ottenere un incremento di performance replicando l'idea dello switch() (magari fino ad 10/15 parametri) per poi ripiegare sulla reflection nel caso in cui il numero di parametri non sia stato gestito precedentemente.