-
-
Notifications
You must be signed in to change notification settings - Fork 934
Closed
Labels
Description
Feature request
https://phpstan.org/r/8b50b60a-9c0c-4627-a6c6-103bbe6802a9
/** @param list<array<string, mixed>> $input */
public function sayHello(array $input): void
{
// improvement request: phpstan should suggest adding `unset($item)` after the foreach statement
// only for loops with variable passed by reference
foreach ($input as &$item) {}
// this is the problem code: it changes last array element
// this code is almost certanly reuses variable by mistake
// and overwrites the last array element by mistake
$item = 'foo';
// bug: phpstan doesn't detect the $input type is changed now
\PHPStan\dumpType($input);
}Did PHPStan help you today? Did it make you happy in any way?
💯 the best utility!