2021-06-17 06:40:24 +02:00
|
|
|
# UnusedForeachValue
|
|
|
|
|
|
|
|
Emitted when `--find-dead-code` is turned on and Psalm cannot find any
|
|
|
|
references to the foreach value
|
|
|
|
|
|
|
|
```php
|
|
|
|
<?php
|
|
|
|
|
2021-06-21 19:57:53 +02:00
|
|
|
/** @param array<string, int> $a */
|
2021-06-17 06:40:24 +02:00
|
|
|
function foo(array $a) : void {
|
|
|
|
foreach ($a as $key => $value) { // $value is unused
|
2021-06-21 19:57:53 +02:00
|
|
|
echo $key;
|
2021-06-17 06:40:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Can be suppressed by prefixing the variable name with an underscore or naming
|
|
|
|
it `$_`:
|
|
|
|
|
|
|
|
```php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
foreach ([1, 2, 3] as $key => $_val) {}
|
|
|
|
|
|
|
|
foreach ([1, 2, 3] as $key => $_) {}
|
|
|
|
```
|