src/ObjectFactory.php
public static function constructClassInstance( $clazz, $args ) {
		// $args should be a non-associative array; show nice error if that's not the case
		if ( $args && array_keys( $args ) !== range( 0, count( $args ) - 1 ) ) {
			throw new InvalidArgumentException( __METHOD__ . ': $args cannot be an associative array' );
		}

		return new $clazz( ...$args );
	}
public static function constructClassInstance( $clazz, $args ) {
		// $args should be a non-associative array; show nice error if that's not the case
		if ( $args && array_keys( $args ) !== range( 0, count( $args ) - 1 ) ) {
			throw new InvalidArgumentException( __METHOD__ . ': $args cannot be an associative array' );
		}

		return new $clazz( ...$args );
	}
public static function constructClassInstance ( $ clazz , $ args ) { // $args should be a non-associative array; show nice error if that's not the case if ( $ args && array_keys ( $ args ) !== range ( 0 , count ( $ args ) - 1 ) ) { throw new InvalidArgumentException ( __METHOD__ . ': $args cannot be an associative array' ) ; } return new $ clazz ( ... $ args ) ; }
Construct an instance of the given class using the given arguments.

@param string $clazz Class name
@param array $args Constructor arguments
@return mixed Constructed instance
Construct an instance of the given class using the given arguments .