Re: Fwd: [PHP-DEV] clarify the destructuring list() concept
| From: | Larry Garfield | Date: | Sat, 06 Jan 2024 16:37:40 +0000 |
| Subject: | Re: Fwd: [PHP-DEV] clarify the destructuring list() concept | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-122134@lists.php.net to get a copy of this message | ||
On Fri, Jan 5, 2024, at 6:22 PM, Mönôme Epson wrote:
> Thank you for your reply. Forgive me for a few mistakes. I'm new to
> Gmail... Is this line "top-post" ?
Yes. Top posting means putting your reply above what people have sent previously. On many mailing
lists, including this one, that is discouraged as it makes the thread harder to follow. Instead,
put your responses inline between parts of what you're replying to, or at the very end. Then
remove any parts of the previous messages not relevant to what you're responding to.
> Le sam. 6 janv. 2024 à 00:48, Larry Garfield <larry@garfieldtech.com> a
> écrit :
>
>> What you can do, as Rowan noted, is this:
>>
>> https://3v4l.org/cEmcC
>>
>> I understood your code. It is interesting when you do not know the order
> of the keys.
> https://3v4l.org/O29NL
> I would have preferred to be able to write:
> https://3v4l.org/o5jkH
> In the same way I do it here:
> https://3v4l.org/I4V3W
>
> I don't see any concrete case where using a variable as a key can be useful
> https://3v4l.org/WR54k
>
> For me it was implemented like this, because it's easier.
>
> In reality, I'm not asking "how" it actually works, but how it should work.
As Rowan notes, how it does work currently is critical, because we need to avoid breaking existing
code. Adding functionality is fine and good, but breaking people's code is not, outside of
some very controlled edge cases.
> list() supports destructuring assignment for arrays. Do you have an opinion
on object destructuring ?
Object destructuring would be better done using pattern matching. Work is already in progress on
that, though it's not yet ready: https://wiki.php.net/rfc/pattern-matching
I get the sense that's much closer to what you are looking for.
--Larry Garfield