Skip to content

Why is $getShared = false the default? #55

Description

@kenjis

In Services, $getShared = false is the default.

    /**
     * The Response class models an HTTP response.
     */
    public static function response(App $config = null, $getShared = false)
    {
        if (! is_object($config))
        {
            $config = new App();
        }

        if (! $getShared)
        {
            return new \CodeIgniter\HTTP\Response($config);
        }

        return self::getSharedInstance('response');
    }

When I want to get the shared object, if I write Services::response(null, true);, it creates new App object.

If the code is like the following, I could write just Services::response().

    public static function response(App $config = null, $getShared = false)
    {
        if ($getShared)
        {
            return self::getSharedInstance('response');
        }

        if (! is_object($config))
        {
            $config = new App();
        }

        return new \CodeIgniter\HTTP\Response($config);
    }

And in the system code, it seems we have more true use cases than false cases.

My question is, do you have any reason that we set the default false?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions