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 <vol...@tideways-gmbh.com> wrote:


On Thu, May 15, 2025 at 12:10 AM Larry Garfield <la...@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

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

Reply via email to