Skip to content
This repository was archived by the owner on Dec 31, 2022. It is now read-only.
This repository was archived by the owner on Dec 31, 2022. It is now read-only.

Return $this directly without using clone class instance #7

@peter279k

Description

@peter279k

As title, please consider the following sample code firstly:

public function withCookieParams(array $cookieParams) : ServerRequestInterface
{
     $clone = clone $this;
     $clone->cookieParams = $cookieParams;
     return $clone;
}

How about using the following code?

public function withCookieParams(array $cookieParams) : ServerRequestInterface
{
     $this->cookieParams = $cookieParams;
     return $this;
}

I think using the clone to clone $this instance is not necessary because it should override the methods/attributes on $this class instance.

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