Re: [RFC] [Discussion] Clone with

From: Date: Tue, 13 Jun 2023 15:51:20 +0000
Subject: Re: [RFC] [Discussion] Clone with
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  Groups: php.internals 
Request: Send a blank email to internals+get-120563@lists.php.net to get a copy of this message
Hi Larry, In this case, if the with happens first, then the new address object is > cloned needlessly, but that *probably* doesn't hurt anything. But $newAddr > !== $p3->address. > Yes, I agree with this: "clone $this with ["x" => "y"];" is the easiest to mentally model as a shorthand for "$self = clone $this; $self->x = "y";". If we agree with this model, then it would be weird to execute __clone() at the end indeed. But I think Nicolas' example explained this fact much better than I could. :) Also, separating __clone() from the rest of the clone opcode would be . And you are right, some objects may be cloned unnecessarily, which doesn't hurt, but isn't ideal for sure. I should mention that in ideal circumstances (when all properties are readonly + all of them are initialized during construction + none of them are mutable internally), deep cloning is not 100% required, unless only for defensive programming purposes. Regards, Máté

« previous php.internals (#120563) next »