Re: [RFC] [Discussion] Clone with

From: Date: Thu, 20 Apr 2023 14:39:37 +0000
Subject: Re: [RFC] [Discussion] Clone with
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-120081@lists.php.net to get a copy of this message
Hi On 4/20/23 16:17, Larry Garfield wrote:
On Thu, Apr 20, 2023, at 7:00 AM, Rowan Tommins wrote:
Rather than making everything use an array or array-like syntax, I would probably go the other way and scrap the special syntax for dynamic names, making the whole thing look like a function call, with support for array unpacking: $point = clone $point with (x: $x, y: $y, z: $z); $point = clone $point with (...['x' => $x, 'y' => $y, 'z' => $z]);
I agree here, for all the reasons Rowan indicated. We already have a perfectly good syntax and semantics for named arguments that supports splat. Using that here would handle all the use cases we care about, including dynamic names, without any additional syntax.
FWIW I'm not too attached to my array proposal [1]. I would also be fine with Rowan's proposal of making the "with()" syntactically identical to a function call, if that's more agreeable. But please no entirely new syntax with braces as it currently is shown in the examples in the RFC. Best regards Tim Düsterhus [1] Though I still consider arrays to be more "natural" than named arguments.

« previous php.internals (#120081) next »