private function getInstance($class, array $args)
    {
        // Hack to avoid Reflection for most cases
        switch (count($args)) {
            case 0:
                return new $class;
            case 1:
                return new $class($args[0]);
            case 2:
                return new $class($args[0], $args[1]);
            case 3:
                return new $class($args[0], $args[1], $args[2]);
            case 4:
                return new $class($args[0], $args[1], $args[2], $args[3]);
            case 5:
                return new $class($args[0], $args[1], $args[2], $args[3], $args[4]);
            case 6:
                return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]);
            default:
                $reflection = new ReflectionClass();
                return $reflection->newInstanceArgs($args);
        }
    }
private function getInstance($class, array $args)
    {
        // Hack to avoid Reflection for most cases
        switch (count($args)) {
            case 0:
                return new $class;
            case 1:
                return new $class($args[0]);
            case 2:
                return new $class($args[0], $args[1]);
            case 3:
                return new $class($args[0], $args[1], $args[2]);
            case 4:
                return new $class($args[0], $args[1], $args[2], $args[3]);
            case 5:
                return new $class($args[0], $args[1], $args[2], $args[3], $args[4]);
            case 6:
                return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]);
            default:
                $reflection = new ReflectionClass();
                return $reflection->newInstanceArgs($args);
        }
    }
private function getInstance ( $ class , array $ args ) { // Hack to avoid Reflection for most cases switch ( count ( $ args ) ) { case 0 : return new $ class ; case 1 : return new $ class ( $ args [ 0 ] ) ; case 2 : return new $ class ( $ args [ 0 ] , $ args [ 1 ] ) ; case 3 : return new $ class ( $ args [ 0 ] , $ args [ 1 ] , $ args [ 2 ] ) ; case 4 : return new $ class ( $ args [ 0 ] , $ args [ 1 ] , $ args [ 2 ] , $ args [ 3 ] ) ; case 5 : return new $ class ( $ args [ 0 ] , $ args [ 1 ] , $ args [ 2 ] , $ args [ 3 ] , $ args [ 4 ] ) ; case 6 : return new $ class ( $ args [ 0 ] , $ args [ 1 ] , $ args [ 2 ] , $ args [ 3 ] , $ args [ 4 ] , $ args [ 5 ] ) ; default : $ reflection = new ReflectionClass ( ) ; return $ reflection -> newInstanceArgs ( $ args ) ; } }
Builds and returns an instance of a class

@param string $class PSR-0 compliant class name
@param array $args Arguments to be passed to class's constructor
@return object
Builds and returns an instance of a class