-
-
Notifications
You must be signed in to change notification settings - Fork 686
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 reference assignment #4371
Conversation
…orphp/rector into downgrade-list-reference-assignment
@TomasVotruba I need your input here. I'm checking if this use case is downgradable: $array = [[1, 2], [3, 4]];
foreach ($array as list(&$a, $b)) {
$a = 7;
}
var_dump($array);
/*
array(2) {
[0]=>
array(2) {
[0]=>
int(7)
[1]=>
int(2)
}
[1]=>
array(2) {
[0]=>
&int(7)
[1]=>
int(4)
}
}
*/ According to the RFC this is not downgradable:
After running this PHP code, the reference exists on If we didn't care about the references, but only about the final values, this is doable: $array = [[1, 2], [3, 4]];
foreach ($array as &$item) {
$item[0] = 7;
}
var_dump($array);
/*
array(2) {
[0]=>
array(2) {
[0]=>
int(7)
[1]=>
int(2)
}
[1]=>
&array(2) {
[0]=>
int(7)
[1]=>
int(4)
}
}
*/ Notice how the reference at the end points to the 2nd item in the array, and not to the 1st element of that item. Hence, the final references cannot be recreated, but the values can. So, what to do? I see 2 options:
Or maybe a bit more complex:
What do you think? |
I thought a better alternative:
|
Or maybe we could create a new set |
Otherwise this rule is ready. So I'll remove it from draft, and you can decide if to already ship it |
I think we can go for low hanging fruit now and test it in the wild. Just not to waste time on problem that might have 1 person from million. If it will cause troubles, we can improve it :) |
Thank you 👍 |
Ok, but we need to discuss this as a concept. This is just one example of a functionality that cannot be downgraded without side-effects. I actually think that having a set We can talk about it on our next meeting. Btw, if you can generate a tag that would be cool, so I can already publicize this new set |
Set names makes sense 👍 I'll release it today |
rectorphp/rector-src@7ee89b3 [BetterPhpDocParser] Remove double array_values() call on same variable (#4371)
Fixes #4315