-
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
Variable reported as unused on an assignment by reference #305
Comments
Reproduced and I have a test case for this. Thanks for the report! I think what's happening is that the scope created by the if/else blocks is not correctly being interpreted as part of the enclosing (function) scope... or somehow there's a mismatch between the code that identifies writes to reference variables as "use" of that variable. |
Interesting. It turns out it's the This exposes two bugs. First, the expression Second, when we process the assignment-by-reference inside the For example, this is the intended behavior: $foo = &$bar; // Warning that $foo is unused because once it is reassigned, it is a different variable.
$foo = &$yaz;
echo $foo; When we reach the end of the scope, and at that point the variable This should not trigger a warning: if ( $x ) {
$foo = &$bar;
} else {
$foo = &$yaz;
}
echo $foo; |
I have the following code
(Last line added to illustrate that the variable is indeed "used").
It reports that
$element
is an unused variable in the first line it appears.If I initialize
$element
the phpcs warning is gone but it should be possible to declare a variable like that.The text was updated successfully, but these errors were encountered: