Static code analyzers like (in this specific case) PHPMD bemoan an error in the following piece of PHP code:
foreach ($aSomething as $key => $value) {
... do something with the $key only
}
The error:
Avoid unused local variables such as '$value'.
Now, I am not aware of any way to create a foreach loop with only the keys. What would be the "analyzer safe" solution to phrase these lines?
I am solving this at the moment via a call to array_keys
and then foreach-ing over this one but it feels like overkill. Another solution is always to silence the analyzer for this loop.
What is the "right" way to keep in line with code quality and "understandability" of code requirements?