Skip to content

Ignore double assignment by reference if second is inside condition #235

New issue

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

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

Already on GitHub? # to your account

Merged
merged 6 commits into from
Jun 18, 2021

Conversation

sirbrillig
Copy link
Owner

@sirbrillig sirbrillig commented Jun 18, 2021

When there are two assignments by reference with use of the variable between them, we consider the first assignment to be unused since it is immediately replaced:

$foo = &$bar; // unused
$foo = &$baz;
echo $foo;

However, if the second assignment is inside a condition, then we can't know if it will be used so we must ignore the warnings there:

$foo = &$bar;
if ($something) {
  $foo = &$baz;
}
echo $foo;

This PR makes that change.

Fixes #231

@sirbrillig sirbrillig merged commit 22c83ec into 2.10 Jun 18, 2021
@sirbrillig sirbrillig deleted the fix-assign-by-reference-and-conditional branch June 18, 2021 20:53
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive detection of "unused variable" when assigned by reference.
1 participant