Re: [RFC] Destructuring Coalesce
| From: | Côme Chilliet | Date: | Tue, 08 Nov 2022 17:09:29 +0000 |
| Subject: | Re: [RFC] Destructuring Coalesce | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118987@lists.php.net to get a copy of this message | ||
Le dimanche 16 octobre 2022, 23:11:05 CET Bob Weinand a écrit :
> Hey,
>
> I've written a small RFC about adding coalesce ability to list() destructuring.
>
> This should enhance the ability to easily, concisely and readably destructure arrays with
> default values.
>
> https://wiki.php.net/rfc/destructuring_coalesce
> <https://wiki.php.net/rfc/destructuring_coalesce>
>
> Bob
Hello,
I voted no as the syntax is too confusing. It reads as if coalescing would happen on the var while
it happens on the array value.
It means $a ?? 'value' would mean something different when in a list context.
It also looks wrong with keys:
list("name" => $name ?? "unknown") = json_decode($json) ?: [];
I would expect:
list("name" ?? "unknown" => $name) = json_decode($json) ?: [];
But event then it looks fishy since "name" is a key and "unknown" is a value.
I understand the need but I just can’t see a good syntax for it, and the one chosen in the RFC
sure feels not good enough for integration.
Côme