Re: [PHP-DEV] [RFC] Clone with v2

2025-05-20 Thread Nicolas Grekas
Le lun. 19 mai 2025 à 19:06, Andreas Hennings a écrit : > On Mon, 19 May 2025 at 17:13, Nicolas Grekas > wrote: > > > > > > > > Le lun. 19 mai 2025 à 16:30, Andreas Hennings a > écrit : > >> > >> On Fri, 16 May 2025 at 21:59, Nicolas Grekas > >> wrote: > >> > > >> > > >> > > >> > Le jeu. 15 ma

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-19 Thread Andreas Hennings
On Mon, 19 May 2025 at 17:13, Nicolas Grekas wrote: > > > > Le lun. 19 mai 2025 à 16:30, Andreas Hennings a écrit : >> >> On Fri, 16 May 2025 at 21:59, Nicolas Grekas >> wrote: >> > >> > >> > >> > Le jeu. 15 mai 2025 à 16:06, Larry Garfield a >> > écrit : >> >> >> >> On Thu, May 15, 2025, at 1

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-19 Thread Nicolas Grekas
Le lun. 19 mai 2025 à 16:30, Andreas Hennings a écrit : > On Fri, 16 May 2025 at 21:59, Nicolas Grekas > wrote: > > > > > > > > Le jeu. 15 mai 2025 à 16:06, Larry Garfield a > écrit : > >> > >> On Thu, May 15, 2025, at 1:22 AM, Stephen Reay wrote: > >> > >> > I may be missing something here.. >

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-19 Thread Andreas Hennings
On Fri, 16 May 2025 at 21:59, Nicolas Grekas wrote: > > > > Le jeu. 15 mai 2025 à 16:06, Larry Garfield a écrit : >> >> On Thu, May 15, 2025, at 1:22 AM, Stephen Reay wrote: >> >> > I may be missing something here.. >> > >> > So far the issues are "how do we deal with a parameter for the actual >

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-19 Thread Volker Dusch
On Fri, May 16, 2025 at 8:46 PM Rowan Tommins [IMSoP] wrote: > However, readonly properties are "protected(set)" by default, so the > situations where this can happen are actually quite limited: > > - Code inside the class itself (private scope) can reasonably be > considered to be "opting in" t

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-17 Thread Volker Dusch
I forgot to mention that on the flip side, this would allow `public public(set) readonly` properties to be "overwritten" after __clone touched them; which is why we chose the more "locked down" version in the first place. So I want to consider this before just updating the RFC :)

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-17 Thread Volker Dusch
On Fri, May 16, 2025 at 9:41 PM Nicolas Grekas wrote: Being able to update a readonly property even if __clone already touched it > looks critical to me because otherwise, it'd mean that adding a __clone > method after publishing a first version of some class that has no __clone > method would be

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-16 Thread Nicolas Grekas
Le jeu. 15 mai 2025 à 16:06, Larry Garfield a écrit : > On Thu, May 15, 2025, at 1:22 AM, Stephen Reay wrote: > > > I may be missing something here.. > > > > So far the issues are "how do we deal with a parameter for the actual > > object, vs new properties to apply", "should __clone be called b

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-16 Thread Nicolas Grekas
Le jeu. 15 mai 2025 à 15:55, Tim Düsterhus a écrit : > Hi > > Am 2025-05-15 00:04, schrieb Larry Garfield: > > Subtle point here. If the __clone() method touches a readonly > > property, does that make the property inaccessible to the new > > clone-with? > > Yes. Quoting from the RFC: > > > The

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-16 Thread Rowan Tommins [IMSoP]
On 15/05/2025 18:56, Stephen Reay wrote: I agree that no __clone and an empty __clone should behave the same way. But as I said, I believe they should behave the same way as they do *now*, until the developer opts in to support cloning with new values. I think what Andreas is saying is that t

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-16 Thread Rob Landers
On Thu, May 15, 2025, at 22:11, Larry Garfield wrote: > On Thu, May 15, 2025, at 2:56 PM, Rob Landers wrote: > > On Thu, May 15, 2025, at 17:32, Tim Düsterhus wrote: > >> Hi > >> > >> Am 2025-05-15 14:14, schrieb Rob Landers: > >> > For example, if you have a Money type, you'd want to be able to e

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-16 Thread Dmitry Derepko
I really like a way with arrays. It allows users to combine what properties they want to re-set and call the clone function only once. Really good catch. On May 15, 2025, at 9:09 PM, Volker Dusch wrote:On Thu, May 15, 2025 at 12:10 AM Larry Garfield wrote:> Please include

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-15 Thread Stephen Reay
> On 15 May 2025, at 23:49, Andreas Hennings wrote: > > On Thu, 15 May 2025 at 13:56, Stephen Reay > wrote: >> >> >> >> >>> On 15 May 2025, at 16:44, Andreas Hennings wrote: >>> >>> On Thu, 15 May 2025 at 08:24, Stephen Reay >>> wrote: >>> [..] >

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-15 Thread Larry Garfield
On Thu, May 15, 2025, at 2:56 PM, Rob Landers wrote: > On Thu, May 15, 2025, at 17:32, Tim Düsterhus wrote: >> Hi >> >> Am 2025-05-15 14:14, schrieb Rob Landers: >> > For example, if you have a Money type, you'd want to be able to ensure >> > it cannot be negative when updating via `with()`. This

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-15 Thread Rob Landers
On Thu, May 15, 2025, at 17:32, Tim Düsterhus wrote: > Hi > > Am 2025-05-15 14:14, schrieb Rob Landers: > > For example, if you have a Money type, you'd want to be able to ensure > > it cannot be negative when updating via `with()`. This is super > > important for ensuring constraints are met

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-15 Thread Volker Dusch
On Thu, May 15, 2025 at 12:10 AM Larry Garfield wrote: > Please include this in the RFC. Done > The concern is someone calling clone($foo, object: new Thingie()), which would complain that "object" is defined twice. Making the first argument named __object sidesteps that issue > If someone then

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-15 Thread Andreas Hennings
On Thu, 15 May 2025 at 13:56, Stephen Reay wrote: > > > > > > On 15 May 2025, at 16:44, Andreas Hennings wrote: > > > > On Thu, 15 May 2025 at 08:24, Stephen Reay > > wrote: > > [..] > >> > >> > >> I may be missing something here.. > >> > >> So far the issues are "how do we deal with a paramet

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-15 Thread Stephen Reay
> On 15 May 2025, at 16:44, Andreas Hennings wrote: > > On Thu, 15 May 2025 at 08:24, Stephen Reay wrote: > [..] >> >> >> I may be missing something here.. >> >> So far the issues are "how do we deal with a parameter for the actual >> object, vs new properties to apply", "should __clon

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-15 Thread Tim Düsterhus
Hi Am 2025-05-15 14:14, schrieb Rob Landers: For example, if you have a Money type, you'd want to be able to ensure it cannot be negative when updating via `with()`. This is super important for ensuring constraints are met during the clone. That's why the assignments during cloning work exact

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-15 Thread Larry Garfield
On Thu, May 15, 2025, at 8:53 AM, Tim Düsterhus wrote: > Hi > > Am 2025-05-15 00:04, schrieb Larry Garfield: >> Subtle point here. If the __clone() method touches a readonly >> property, does that make the property inaccessible to the new >> clone-with? > > Yes. Quoting from the RFC: > >> The cu

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-15 Thread Larry Garfield
On Thu, May 15, 2025, at 1:22 AM, Stephen Reay wrote: > I may be missing something here.. > > So far the issues are "how do we deal with a parameter for the actual > object, vs new properties to apply", "should __clone be called before > or after the changes" and "this won't allow regular read

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-15 Thread Tim Düsterhus
Hi Am 2025-05-15 00:04, schrieb Larry Garfield: Subtle point here. If the __clone() method touches a readonly property, does that make the property inaccessible to the new clone-with? Yes. Quoting from the RFC: The currently linked implementation “locks” a property if it modified within __

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-15 Thread Rob Landers
On Thu, May 15, 2025, at 13:56, Stephen Reay wrote: > > > > > On 15 May 2025, at 16:44, Andreas Hennings wrote: > > > > On Thu, 15 May 2025 at 08:24, Stephen Reay > > wrote: > > [..] > >> > >> > >> I may be missing something here.. > >> > >> So far the issues are "how do we deal with a p

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-15 Thread Andreas Hennings
On Thu, 15 May 2025 at 08:24, Stephen Reay wrote: [..] > > > I may be missing something here.. > > So far the issues are "how do we deal with a parameter for the actual object, > vs new properties to apply", "should __clone be called before or after the > changes" and "this won't allow regular

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-14 Thread Stephen Reay
> On 15 May 2025, at 06:26, Volker Dusch wrote: > > On Wed, May 14, 2025 at 10:06 PM Matthew Weier O'Phinney > mailto:mweierophin...@gmail.com>> wrote: > > > The only question that arose for me is: what happens if a property name is > > provided to `clone()` that does not exist in the class d

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-14 Thread Volker Dusch
On Wed, May 14, 2025 at 10:06 PM Matthew Weier O'Phinney < mweierophin...@gmail.com> wrote: > The only question that arose for me is: what happens if a property name is provided to `clone()` that does not exist in the class definition; what will be the behavior at that time? Will an exception or e

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-14 Thread Larry Garfield
On Wed, May 14, 2025, at 2:54 PM, Volker Dusch wrote: > On Wed, May 14, 2025 at 5:40 PM Larry Garfield wrote: >>> A magic __clone() method will be called before the new properties are >>> assigned. >> Why before and not after? I could probably make a good argument either >> direction, but we sh

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-14 Thread Larry Garfield
On Wed, May 14, 2025, at 4:00 PM, Tim Düsterhus wrote: > The internal implementation is roughly equivalent to: > > $cloned = clone $object; > foreach ($withProperties as $key => $value) { > $cloned->{$key} = $value; > } > return $cloned; > > Just with the exception tha

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-14 Thread Tim Düsterhus
Hi Am 2025-05-14 22:06, schrieb Matthew Weier O'Phinney: The only question that arose for me is: what happens if a property name is provided to `clone()` that does not exist in the class definition; what will be the behavior at that time? Will an exception or error be thrown? If so, will it b

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-14 Thread Matthew Weier O'Phinney
On Wed, May 14, 2025 at 8:06 AM Volker Dusch wrote: > A couple of weeks ago, we stumbled over the fact that the original "clone > with" RFC was abandoned and thought it would still be useful to suggest a > trimmed down version of the proposal. > > The main goal of this RFC is to propose a lightwe

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-14 Thread Volker Dusch
On Wed, May 14, 2025 at 5:40 PM Larry Garfield wrote: >> A magic __clone() method will be called before the new properties are assigned. > Why before and not after? I could probably make a good argument either direction, but we should be explicit about why we're making whatever decision. >From a

Re: [PHP-DEV] [RFC] Clone with v2

2025-05-14 Thread Larry Garfield
On Wed, May 14, 2025, at 8:04 AM, Volker Dusch wrote: > Hi internals, > > A couple of weeks ago, we stumbled over the fact that the original > "clone with" RFC was abandoned and thought it would still be useful to > suggest a trimmed down version of the proposal. > > The main goal of this RFC is