On Wed, Jun 3, 2020 at 11:37 AM paul laffitte <paul.laffi...@epitech.eu>
wrote:

> 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.
>

To give a tl;dr of existing discussions on the topic:

    $foobar = [2 => 2, 1 => 1, 0 => 0];
    [$foo, ...$bar] = $foobar;
    // What is the result?

Introducing this feature is primarily a matter of coming up with a
satisfactory answer to the above question. (There is an existing constraint
that $foo must be equal to 0 in this case, not 2.)

Regards,
Nikita

Reply via email to