Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Downgrade PHP 7.3] list() and array destructuring reference assignment #4315

Closed
leoloso opened this issue Sep 29, 2020 · 1 comment · Fixed by #4371
Closed

[Downgrade PHP 7.3] list() and array destructuring reference assignment #4315

leoloso opened this issue Sep 29, 2020 · 1 comment · Fixed by #4371

Comments

@leoloso
Copy link
Contributor

leoloso commented Sep 29, 2020

Feature Request

Downgrade new feature from PHP 7.3 to its equivalent PHP 7.2 code. RFC with explanation

This feature must be handled with care. Check in the RFC all the nuances, and if there is any instance where downgrading is not possible, identify that case in the rule and throw a DowngradeNotPossibleException.

Diff

$array = [1, 2];
-list($a, &$b) = $array;
+$a = $array[0];
+$b =& $array[1];

/* Note; []= syntax works the same, so the following is functionally equivalent to the example */
-[$a, &$b] = $array;
+$a = $array[0];
+$b =& $array[1];
@leoloso
Copy link
Contributor Author

leoloso commented Oct 8, 2020

The solution involves 2 steps:

  1. Remove the references from list
  2. Add new nodes to override those assignments, doing it by reference with the supported =& operator
$array = [1, 2];
-list($a, &$b) = $array;
+list($a, $b) = $array;
+$b =& $array[1];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant