B
B
BonBon Slick2018-05-04 17:45:02
Software design
BonBon Slick, 2018-05-04 17:45:02

Update Object Value?

public function change(string $email) : self
    {
        $copy = clone $this;
        $copy->email = $email;
        $this->validate();

        return $copy;
    }

Or
public function change(string $email)
{
   $this->validate($email);    
  return new self(
        $email
    );
}

I think you can come up with a couple more ways to replace and create a new object.
Which option is preferred and why? Is there a performance difference?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question