public static function create($className, $arguments = null, $constructor = null, $reflection = null)
    {
        // get reflection if not passed
        if (!$reflection) {
            $reflection = new ReflectionClass($className);
        }

        // check for given arguments
        if ($arguments) {
            // check if parameter is already of type array
            if (!is_array($arguments)) {
                // if not make array
                $arguments = [$arguments];
            }

            // return instance with parameter
            return $reflection->newInstanceArgs($arguments);
        } else {
            // return instance without parameter
            return $reflection->newInstance();
        }
    }
public static function create($className, $arguments = null, $constructor = null, $reflection = null)
    {
        // get reflection if not passed
        if (!$reflection) {
            $reflection = new ReflectionClass($className);
        }

        // check for given arguments
        if ($arguments) {
            // check if parameter is already of type array
            if (!is_array($arguments)) {
                // if not make array
                $arguments = [$arguments];
            }

            // return instance with parameter
            return $reflection->newInstanceArgs($arguments);
        } else {
            // return instance without parameter
            return $reflection->newInstance();
        }
    }
public static function create ( $ className , $ arguments = null , $ constructor = null , $ reflection = null ) { // get reflection if not passed if ( ! $ reflection ) { $ reflection = new ReflectionClass ( $ className ) ; } // check for given arguments if ( $ arguments ) { // check if parameter is already of type array if ( ! is_array ( $ arguments ) ) { // if not make array $ arguments = [ $ arguments ] ; } // return instance with parameter return $ reflection -> newInstanceArgs ( $ arguments ) ; } else { // return instance without parameter return $ reflection -> newInstance ( ) ; } }
This method is intend to create instances of multi-instance-classes. You can
pass optional arguments to the factory for creating instance and passing arguments
to it. You can pass an optional already existing reflection instance of the class
if one exist to speed up instantiation. If you don't use an autoloader the you must
include the file containing the class right before you call this method.

@param string $className   The name of the class to instantiate
@param mixed  $arguments   The arguments to pass to class for instantiation
@param string $constructor NOT USED but part of interface/contract
@param string $reflection  An optional already existing reflection of the class to create

@author Benjamin Carl <opensource@clickalicious.de>

@return object An instance of the requested class
@static
This method is intend to create instances of multi - instance - classes . You can pass optional arguments to the factory for creating instance and passing arguments to it . You can pass an optional already existing reflection instance of the class if one exist to speed up instantiation . If you don t use an autoloader the you must include the file containing the class right before you call this method .