1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00
psalm/docs/running_psalm/issues/UnusedForeachValue.md
Bruce Weirdan e552925af6
Emit separate type of issue when foreach value is unused (#5932)
* Emit separate type of issue when foreach value is unused

Fixes vimeo/psalm#5929

* Fixed var name case sensitivity
2021-06-17 00:40:24 -04:00

502 B

UnusedForeachValue

Emitted when --find-dead-code is turned on and Psalm cannot find any references to the foreach value

<?php

/** @param non-empty-array<string, int> $a */
function foo(array $a) : void {
    foreach ($a as $key => $value) { // $value is unused
        break;
    }
    echo $key;
}

Can be suppressed by prefixing the variable name with an underscore or naming it $_:

<?php

foreach ([1, 2, 3] as $key => $_val) {}

foreach ([1, 2, 3] as $key => $_) {}