Re: [RFC] Clone with v2

From: Date: Thu, 15 May 2025 09:32:04 +0000
Subject: Re: [RFC] Clone with v2
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-127372@lists.php.net to get a copy of this message
On Thu, 15 May 2025 at 08:24, Stephen Reay <php-lists@koalephant.com> 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 readonly properties to be modified".
>
> Isn't the previous suggestion of passing the new property arguments directly to the
> __clone method the obvious solution to all three problems?

What exactly should happen then?
Would the __clone() method be responsible for assigning those properties?
Or does the __clone() method get the chance to alter the values before
they are assigned?
(this would mean they have to be passed by reference)
I think this last option is the best, because the values in the array
can be changed without any readonly constraints.

Another option I was thinking of would be to call __clone() after the
changes are applied, and pass both the original object and the array
of changes as first parameter.
But I think this is a dead end.

-- Andreas

>
> There's no potential for a conflicting property name, the developer can use the new
> property values in the order they see fit relative to the logic in the __clone call, and it's
> inherently in scope to write to any (unlocked during __clone) readonly properties.
>
>
>
> Cheers
>
> Stephen
>
>
>


Thread (52 messages)

« previous php.internals (#127372) next »