Fwd: [PHP-DEV] clarify the destructuring list() concept

Mönôme Epson <[email protected]>
Newsgroups gmane.comp.php.devel,gmane.comp.php.general
Message-ID <CADeZBNZnsEsxwbikGgruUfsbJtb7z4_Dg+7xrMNwYA+kpFwbOQ@mail.gmail.com>
---------- Forwarded message ---------
De : Mönôme Epson <[email protected]>
Date: sam. 6 janv. 2024 à 00:15
Subject: Re: [PHP-DEV] clarify the destructuring list() concept
To: Rowan Tommins <[email protected]>




Le ven. 5 janv. 2024 à 23:31, Rowan Tommins <[email protected]> a
écrit :

>
> I'm not sure what your question is



I try to follow the procedure of: https://wiki.php.net/rfc/howto

It seems to me that list() is not clearly specified.
I wanted to know your opinions on this.


For example :
$key = "a";
$value = 1;
$array = [$key => $value];

[$key => $value] = $array;

We all agree that now $key = 'a' and $value = 1

And I wonder why
What happens in this case :

[$key => $value] = ['b'=>2];

$key = 'b' and $value = 2 or all is null ?

Le ven. 5 janv. 2024 à 23:31, Rowan Tommins <[email protected]> a
écrit :

> The name for this if you want to find more information is "array
> destructuring".


list() supports destructuring assignment for arrays. Do you have an opinion
on object destructuring ?

*Do you think seeing list() as the reciprocal of a function call is
interesting ?*

Otherwise, how to use a default value, type hinting, nullable/optional
variable... It's not interesting ?

There are many things that could be done with but don't work. For example :

$array = [1, 2, 3];
[...$values] = [...$array];

My question is: I see list() as the reciprocal of an array(). Do you think
it would be interesting for everyone if I proposed my vision?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.