Re: [RFC] [Discussion] Clone with
| From: | Larry Garfield | Date: | Thu, 20 Apr 2023 14:15:29 +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-120079@lists.php.net to get a copy of this message | ||
On Thu, Apr 20, 2023, at 7:22 AM, Aleksander Machniak wrote:
> On 20.04.2023 09:00, 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]);
>
> or $point = clone($point, x: $x, y: $y, z: $z);
>
> Also, I didn't see it mentioned, but maybe for future scope, these new
> arguments should be passed to __clone().
They should not. See https://peakd.com/hive-168588/@crell/object-properties-part-2-examples
. I went through and experimented with different syntaxes, and passing arguments to __clone() was
by far the worst option in practice. :-)
--Larry Garfield