X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Flibs%2FObjectFactory.php;h=c96a8a1643e78639dc6bc5aa006ecc458a5a3124;hb=a24e2312c14ab772c65cafd06f909d6a137d53d4;hp=61916120fdf6677aa97e1a142473b7ec1c01a72d;hpb=fecb2320a8cbe72339a12d204590a7a184b082a3;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/ObjectFactory.php b/includes/libs/ObjectFactory.php index 61916120fd..c96a8a1643 100644 --- a/includes/libs/ObjectFactory.php +++ b/includes/libs/ObjectFactory.php @@ -57,7 +57,7 @@ class ObjectFactory { * constructor is non-public or non-existent */ public static function getObjectFromSpec( $spec ) { - $args = isset( $spec['args'] ) ? $spec['args'] : array(); + $args = isset( $spec['args'] ) ? $spec['args'] : []; $expandArgs = !isset( $spec['closure_expansion'] ) || $spec['closure_expansion'] === true; @@ -86,7 +86,7 @@ class ObjectFactory { if ( $expandArgs ) { $margs = static::expandClosures( $margs ); } - call_user_func_array( array( $obj, $method ), $margs ); + call_user_func_array( [ $obj, $method ], $margs ); } } @@ -128,8 +128,13 @@ class ObjectFactory { * @return mixed Constructed instance */ 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' ); + } + // TODO: when PHP min version supported is >=5.6.0 replace this - // function body with `return new $clazz( ... $args );`. + // with `return new $clazz( ... $args );`. $obj = null; switch ( count( $args ) ) { case 0: