Re: [RFC] Clone with v2

From: Date: Thu, 15 May 2025 17:07:26 +0000
Subject: Re: [RFC] Clone with v2
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-127383@lists.php.net to get a copy of this message
On Thu, May 15, 2025 at 12:10 AM Larry Garfield <larry@garfieldtech..com> 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 Dusch Head of Engineering Tideways GmbH Königswinterer Str. 116 53227 Bonn https://tideways.io/imprint Sitz der Gesellschaft: Bonn Geschäftsführer: Benjamin Außenhofer (geb. Eberlei) Registergericht: Amtsgericht Bonn, HRB 22127

« previous php.internals (#127383) next »