You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the default configuration (phpcs --standard=VariableAnalysis -s phpcs-test.php), this is detected as "Unused variable $unused_variable (VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable)". ✅
Snippet 2:
<?php$unused_variable = 'foo';
?>
The addition of the ?> stops the violation from being reported, even though the variable is still unused. ❌
Tested in VA 2.11.0.
The text was updated successfully, but these errors were encountered:
GaryJones
changed the title
File-scope unused variable not detected when ?> is present.
File-scope unused variable not detected when ?> is present
Jun 17, 2021
That definitely looks like a bug. I hadn't considered files that use closing php tags (since they're generally discouraged) and I suspect that the sniff misidentifies them. We'll need to make it aware of that.
Consider the case of a template file which is most likely to contain file-scope variables, that may include many ?> and <?php as it breaks from PHP to HTML and back, then accounting for the ?> seems like an important thing :-)
Snippet 1:
With the default configuration (
phpcs --standard=VariableAnalysis -s phpcs-test.php
), this is detected as "Unused variable $unused_variable (VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable)". ✅Snippet 2:
The addition of the
?>
stops the violation from being reported, even though the variable is still unused. ❌Tested in VA 2.11.0.
The text was updated successfully, but these errors were encountered: