Hello everyone,

On Mon, May 29, 2023 at 6:48 AM Michał Marcin Brzuchalski
<michal.brzuchal...@gmail.com> wrote:

> So there would be no option to vote on shorthand properties, right?
>
> Array syntax with all properties as strings in quotes probably means no
> support from IDE.
> I think this is a really bad move, I'd be against it.

I agree. I think going to a single syntax was a good move, but using the literal
property name would have been better imo.

I really think the syntax would benefit from being more similar to
function calls,
with a syntax like:

clone $obj with (prop1: "value");

This brings the familiarity from named arguments, which in this case would
represent the object's properties.

Then for dynamic property name support, you can borrow array unpacking
into an argument list from function calls as well, allowing the dynamic
properties to be set like:

$myProp = 'prop1';
clone $obj with (...[$myProp => 'value']);

This also gives the ability to have create dynamic properties via anonymous
function as well, like so:

$myFunc = function ($original): array {
    $props = [];
    // add results
    return $props;
};
clone $obj with (...$myFunc($obj));

You even have the ability to pass it whatever you want including the original
object to operate off of.

Regards,
Brandon Jackson

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to