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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





---------- Forwarded message ---------
De : Mönôme Epson <glash.gnome@xxxxxxxxx>
Date: sam. 6 janv. 2024 à 00:15
Subject: Re: [PHP-DEV] clarify the destructuring list() concept
To: Rowan Tommins <rowan.collins@xxxxxxxxx>




Le ven. 5 janv. 2024 à 23:31, Rowan Tommins <rowan.collins@xxxxxxxxx> 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@xxxxxxxxx> 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?


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux