-
Notifications
You must be signed in to change notification settings - Fork 15
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
List assignment next to array causes unused variable warning #317
Comments
Thanks for the report!
I think you're right because this passes: static function foo(DBC $db, int $notificationId): void {
list($bar) = $db->queryGetRowIndexed('SELECT blah... ', [ 'n.notificationId' => $notificationId ]);
echo $bar;
} Whereas this fails: static function foo(DBC $db, int $notificationId): void {
[$bar] = $db->queryGetRowIndexed('SELECT blah... ', [ 'n.notificationId' => $notificationId ]);
echo $bar;
} Even though both are destructuring. What's really weird is that the warning is Here's a more minimal case with the same bug: function foo(int $baz) {
[$bar] = doSomething([$baz]);
return $bar;
} Investigating... |
#318 should fix the issue you found, although you'll still get an unused variable warning in your first example unless you do something with As for the second issue, function dotToMultiArray( array $array ): array {
$multi = [];
foreach($array as $key => $value){
$level = &$multi; // $level is assigned
foreach(explode(".", $key) as $node)
$level = &$level[$node]; // $level is assigned again
$level = $value; // $level is assigned a third time
}
return $multi; // We ignore $level and return $multi
} In this case, I think that example is equivalent to: function dotToMultiArray( array $array ): array {
$multi = [];
return $multi;
} |
Yes, the function wasn't complete and Re the second case, |
Interesting... Does that actually work to run |
Oh! It does. Wild. I made #319 to investigate that one. |
This bit is throwing a
VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
false positive for$notificationId
. It seems it has to do with array destructuring the result, because if changed to$bar
it disappears.And this one too, in
$level
, although in this case it looks related to that "self reference assignment":The text was updated successfully, but these errors were encountered: