Array count is not invalidated when items are unset leading to false negatives
Bug report
Since: 2.1.34
PHPStan appears to cache the first call to count as int<1, max> and then further calls to count report errors with comparison operators such as greater.alwaysTrue, even though the array may have been mutated with unset.
Inlined Example Code
$list = [ 'a', 'b', 'c', ]; /** @param list<string> $list */ function acceptList(array $list): bool { if (count($list) < 1) { return false; } $compare = ['a', 'b', 'c']; foreach($list as $key => $item) { foreach ($compare as $k => $v) { if ($item === $v && $v !== 'a') { unset($list[$key]); } } } if (count($list) > 0) { return true; } return false; } assert(acceptList($list) === true);
Code snippet that reproduces the problem
https://phpstan.org/r/40d2cb57-5926-4ffd-b1c9-8492d3c812e3
Expected output
No errors
Did PHPStan help you today? Did it make you happy in any way?
Thanks for PHPStan! Great perf improvements in the latest release 👍