sirbrillig / phpcs-variable-analysis

Find undefined and unused variables with the PHP Codesniffer static analysis tool.
Other
136 stars 14 forks source link

Variable not marked as used in short open echo tag #323

Closed biinari closed 4 months ago

biinari commented 4 months ago

Problem

A variable is not counted as used in a short open echo tag:

<?php
$a = 'foo'; // incorrectly marked as UnusedVariable
?>
<p><?= $a ?></p>

Cases that currently work

The sniff will correctly identify this variable as used if another statement follows it (or another short open echo tag):

<?php
$a = 'foo';
?>
<p><?= $a ?></p>
<p><?= 'more' ?></p>

It also correctly identifies the variable as used if the short echo tag includes a semicolon:

<?php
$a = 'foo';
?>
<p><?= $a; ?></p>