Re: [RFC] Clone with v2

From: Date: Fri, 16 May 2025 08:40:01 +0000
Subject: Re: [RFC] Clone with v2
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
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 <[email protected]> wrote:On Thu, May
15, 2025 at 12:10 AM Larry Garfield <[email protected]> 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 calls clone(prop: 'new val', __object: $foo),
that... I suppose would technically compile, but one should never do that, and I am perfectly happy
if that breaks.  Similar for if someone called clone(prop: 'new val', object: $foo) if we
didn't rename that parameter.  No one should be doing that and I am fine if that breaks

Yes. I think we're on the same page here. But just to be clear, I'll restate it again with
my own words:

Whatever the first parameter (the to-be-cloned object) of the clone() function is called will be
completely inaccessible as a property name. 

clone($foo, __object: "bar") will fail (Named parameter overwrites previous
argument)clone($foo, ...["__object" => "bar"]) will also fail. 

While clone(prop: 'new val', __object: $foo) just works.

For example, using the current implementation where the parameter is named
object:```class Foo {    public int $bar;}$x = new Foo();var_dump(clone(bar: 5,
object: $x));

// object(Foo)#2 (1) {//   ["bar"]=>//   int(5)// }```

-- Volker DuschHead of EngineeringTideways GmbHKönigswinterer Str. 11653227 Bonnhttps://tideways.io/imprint

Sitz der Gesellschaft: BonnGeschäftsführer: Benjamin Außenhofer (geb. Eberlei)Registergericht:
Amtsgericht Bonn, HRB 22127



Thread (26 messages)

« previous php.internals (#127387) next »