-
-
Notifications
You must be signed in to change notification settings - Fork 933
Closed
Labels
Milestone
Description
Bug report
When iterating on 2 (or more) dimensional array the error: Comparison operation ">" between int<1, max> and 0 is always true. is incorrectly returned.
Code snippet that reproduces the problem
<?php declare(strict_types = 1);
$map = [
1 => 'foo',
2 => 'foo',
3 => 'bar',
];
$names = ['foo', 'bar', 'baz'];
$array = ['foo' => [], 'bar' => [], 'baz' => []];
foreach ($map as $value => $name) {
$array[$name][] = $value;
}
foreach ($array as $name => $elements) {
echo sprintf('"%s" -> "%d".' . PHP_EOL, $name, count($elements) > 0);
}
(https://phpstan.org/r/8787a548-d915-4658-832f-dc3e7575884e)
Expected output
No error, as it is false positive: https://3v4l.org/6eAMe
Real life case can be found here: https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/5805/files#diff-a809d26a7ee19fceeb074078036812dc5c022e0a52d7ef0cc27d13cd161b33dfR569 - when you remove the condition that is claimed to be always true some tests start to fail