public function newInstance($class, array $params = array()) {
        if (is_callable($class)) {
            return call_user_func_array($class, $params);
        }

        switch (count($params)) {
            case 0:
                return new $class();
            case 1:
                return new $class($params[0]);
            case 2:
                return new $class($params[0], $params[1]);
            case 3:
                return new $class($params[0], $params[1], $params[2]);
            case 4:
                return new $class($params[0], $params[1], $params[2], $params[3]);
            case 5:
                return new $class($params[0], $params[1], $params[2], $params[3], $params[4]);
            default:
                try {
                    $refClass = new \ReflectionClass($class);
                    return $refClass->newInstanceArgs($params);
                } catch (\ReflectionException $e) {
                    throw new \Exception("Cannot instantiate {$class}", 0, $e);
                }
        }
    }
public function newInstance($class, array $params = array()) {
        if (is_callable($class)) {
            return call_user_func_array($class, $params);
        }

        switch (count($params)) {
            case 0:
                return new $class();
            case 1:
                return new $class($params[0]);
            case 2:
                return new $class($params[0], $params[1]);
            case 3:
                return new $class($params[0], $params[1], $params[2]);
            case 4:
                return new $class($params[0], $params[1], $params[2], $params[3]);
            case 5:
                return new $class($params[0], $params[1], $params[2], $params[3], $params[4]);
            default:
                try {
                    $refClass = new \ReflectionClass($class);
                    return $refClass->newInstanceArgs($params);
                } catch (\ReflectionException $e) {
                    throw new \Exception("Cannot instantiate {$class}", 0, $e);
                }
        }
    }
public function newInstance ( $ class , array $ params = array ( ) ) { if ( is_callable ( $ class ) ) { return call_user_func_array ( $ class , $ params ) ; } switch ( count ( $ params ) ) { case 0 : return new $ class ( ) ; case 1 : return new $ class ( $ params [ 0 ] ) ; case 2 : return new $ class ( $ params [ 0 ] , $ params [ 1 ] ) ; case 3 : return new $ class ( $ params [ 0 ] , $ params [ 1 ] , $ params [ 2 ] ) ; case 4 : return new $ class ( $ params [ 0 ] , $ params [ 1 ] , $ params [ 2 ] , $ params [ 3 ] ) ; case 5 : return new $ class ( $ params [ 0 ] , $ params [ 1 ] , $ params [ 2 ] , $ params [ 3 ] , $ params [ 4 ] ) ; default : try { $ refClass = new \ ReflectionClass ( $ class ) ; return $ refClass -> newInstanceArgs ( $ params ) ; } catch ( \ ReflectionException $ e ) { throw new \ Exception ( "Cannot instantiate {$class}" , 0 , $ e ) ; } } }
Gets a new instance of a class.

@param string|callable $class Class name or callback function to instantiate class
@param array $params Class initialization parameters
@return object Class instance
@throws \Exception
Gets a new instance of a class .