A local variable is assigned but never read
What it finds
A local variable that a function assigns but never reads: the assignment does nothing, and often a later line meant to use the variable reads another one. Parameters, variables bound by foreach, list, catch, global or static, variables bound by reference, and names that start with $_ or say they are unused are left alone, and so are functions whose variables cannot be known from their text.
From the rule's source, unused_variable.rs.
<?phpfunction compute($items){ $result = [];tx0 reports: $result is assigned but never read $count = count($items); foreach ($items as $key => $item) { echo $item; } [$first, $second] = $items; $_ignored = 1; $total = 0; $total += $count; return $first . $total;} function by_reference(&$list){ $alias = &$list; $alias[] = 1;} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/php:unused-variable" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/php:unused-variable] reason="..."tx0 explain tx0/php:unused-variable shows the same in the terminal. Found a false positive? Report it.