Re: [RFC] [Discussion] Clone with

From: Date: Tue, 30 May 2023 16:58:39 +0000
Subject: Re: [RFC] [Discussion] Clone with
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-120470@lists.php.net to get a copy of this message
Hi On 5/30/23 18:37, Larry Garfield wrote:
To be honest, the current behavior seemed like the natural choice for me, and I didn't really consider to execute the __clone() method after the clone assignments. Do you have a use-case in mind when you need to forward-pass information to __clone()?
Not a specific one off hand. It's more a conceptual question. with has more contextual awareness than __clone(), so it should have "first crack" at the operation, so that if necessary it can make changes that __clone() can then respond to. The inverse doesn't make sense. The only reason for with to come after would be to allow with to "override" or "undo" something that __clone() did. Generally speaking, if you have to undo something you just did, you shouldn't have done it in the first place, so that's a less compelling combination. This one isn't a deal breaker, but we should be sure to think it through as it's kinda hard to reverse later.
FWIW if I would've create the implementation, I intuitively would also have chosen to first execute __clone() and then set the properties. Of course this isn't a well-argued reason to do it this way, but I wanted to share it nonetheless. Best regards Tim Düsterhus

« previous php.internals (#120470) next »