-
-
Notifications
You must be signed in to change notification settings - Fork 947
False positive with in_array when being used in loops #7684
Copy link
Copy link
Closed
phpstan/phpstan-src
#1545Labels
Milestone
Description
Bug report
There is an issue which came up with Version 1.8.1 which was not present in 1.8.0.
The code below is shown as if it contains issues but from my point of view it is more like a false positive since the iteration can and will change the values in $arr.
Instead of a const array we are retrieving objects from the database which can also have a collection of objects which is stored within the $arr variable and therefore can have duplicates which are filtered away in this structure.
Code snippet that reproduces the problem
<?php declare(strict_types = 1);
class SomeClass
{
public function someFunction(int ...$someIntArray): void
{
$arr = [];
foreach ($someIntArray as $val) {
if (in_array($val, $arr, true) === true) {
continue;
}
$arr[] = $val;
}
}
}Expected output
Should not report an error, since the $arr variable is only empty in the first iteration.
Reactions are currently unavailable