Skip to content

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
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 this pull request may close these issues.

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