RFC proposal: Spread Operator for Array Destructuring Assignment
| From: | paul laffitte | Date: | Wed, 03 Jun 2020 09:37:06 +0000 |
| Subject: | RFC proposal: Spread Operator for Array Destructuring Assignment | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-110342@lists.php.net to get a copy of this message | ||
Hello,
I would like to submit an RFC proposal about array destructuring assignment.. An RFC has already
been implemented in php 7.1 about this (https://wiki.php.net/rfc/short_list_syntax), but I feel like
something is missing for this one. Indeed, another RFC about "Spread Operator in Array
Expression" has been implemented in php 7.4
(https://wiki.php.net/rfc/spread_operator_for_array). The first RFC allows to destructure an array
and assign several variable from it, the other one allows to build an array by "spreading
another array inside of it". It would be so nice if we could combine both feature to provide a
spread operator for array destructuring assignment.
Here is a short example to demonstrate it:
$foobar = [1, 2, 3, 4, 5];
[$foo, ...$bar] = $foobar;
So here $foo = 1 and $bar = [2, 3, 4, 5];
During my developer journey, I've encountered several cases where this could be very useful and
make my code shorter.
Best regards,
Paul Laffitte
paul.laffitte@epitech.eu<mailto:paul.laffitte@epitech.eu>
Student Promotion 2021
{EPITECH.} Montpellier
+336.01.04.24.96