Fwd: [PHP-DEV] clarify the destructuring list() concept
| From: | Mönôme Epson | Date: | Fri, 05 Jan 2024 23:16:58 +0000 |
| Subject: | Fwd: [PHP-DEV] clarify the destructuring list() concept | ||
| References: | 1 2 3 | Groups: | php.general php.internals |
| Request: | Send a blank email to internals+get-122128@lists.php.net to get a copy of this message | ||
---------- Forwarded message ---------
De : Mönôme Epson <glash.gnome@gmail.com>
Date: sam. 6 janv. 2024 à 00:15
Subject: Re: [PHP-DEV] clarify the destructuring list() concept
To: Rowan Tommins <rowan.collins@gmail.com>
Le ven. 5 janv. 2024 à 23:31, Rowan Tommins <rowan.collins@gmail.com> 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 <rowan.collins@gmail.com> 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?