public static function getInstance($class)
    {
        $reflection = new ReflectionClass($class);
        $constructor = $reflection->getConstructor();

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

        $parameters = $constructor->getParameters();

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

        $dependencies = array();
        foreach ($parameters as $parameter) {
            $parameter_class = $parameter->getClass();
            $dependencies[] = static::get($parameter_class->getName());
        }

        return $reflection->newInstanceArgs($dependencies);
    }
public static function getInstance($class)
    {
        $reflection = new ReflectionClass($class);
        $constructor = $reflection->getConstructor();

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

        $parameters = $constructor->getParameters();

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

        $dependencies = array();
        foreach ($parameters as $parameter) {
            $parameter_class = $parameter->getClass();
            $dependencies[] = static::get($parameter_class->getName());
        }

        return $reflection->newInstanceArgs($dependencies);
    }
public static function getInstance ( $ class ) { $ reflection = new ReflectionClass ( $ class ) ; $ constructor = $ reflection -> getConstructor ( ) ; if ( empty ( $ constructor ) ) { return new $ class ; } $ parameters = $ constructor -> getParameters ( ) ; if ( empty ( $ parameters ) ) { return new $ class ; } $ dependencies = array ( ) ; foreach ( $ parameters as $ parameter ) { $ parameter_class = $ parameter -> getClass ( ) ; $ dependencies [ ] = static :: get ( $ parameter_class -> getName ( ) ) ; } return $ reflection -> newInstanceArgs ( $ dependencies ) ; }
Returns an instance using a class name
@param string $class
@return object
Returns an instance using a class name