public static function getInstance(string $class, array $params = [])
    {
        if (!class_exists($class)) {
            throw new InvalidArgumentException("Class [$class] does not exist");
        }

        if (empty($params)) {
            return new $class;
        }

        $reflection = new ReflectionClass($class);

        return $reflection->newInstanceArgs($params);
    }
public static function getInstance(string $class, array $params = [])
    {
        if (!class_exists($class)) {
            throw new InvalidArgumentException("Class [$class] does not exist");
        }

        if (empty($params)) {
            return new $class;
        }

        $reflection = new ReflectionClass($class);

        return $reflection->newInstanceArgs($params);
    }
public static function getInstance ( string $ class , array $ params = [ ] ) { if ( ! class_exists ( $ class ) ) { throw new InvalidArgumentException ( "Class [$class] does not exist" ) ; } if ( empty ( $ params ) ) { return new $ class ; } $ reflection = new ReflectionClass ( $ class ) ; return $ reflection -> newInstanceArgs ( $ params ) ; }
Get an instance of a given class

This method is public because it is useful in a variety of
situations, not just for the factory via class map.

@throws \InvalidArgumentException when cannot create instance
@param string $class Class name to instantiate
@param mixed[] $params Optional parameters to the class
@return object
Get an instance of a given class