You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PHPStan 1.8.2 didn't raise an error on this code but starting from 1.8.3 an error is raised, the rules for array_shift()/array_pop() no longer seem to understand that the array can be empty.
Code snippet that reproduces the problem
<?phpdeclare(strict_types = 1);
classHelloWorld
{
/** * @param array{name: string, age: int} $a * @param array{name: string, age: int} $b */publicfunctioncompare(array$a, array$b): int
{
$sort = [
$a['name'] <=> $b['name'],
$a['age'] <=> $b['age'],
];
$sort = array_filter($sort, function (int$value): bool {
return$value !== 0;
});
return array_shift($sort) ?? 0; // Error: Expression on left side of ?? is not nullable.
}
}
Bug report
PHPStan 1.8.2 didn't raise an error on this code but starting from 1.8.3 an error is raised, the rules for
array_shift()
/array_pop()
no longer seem to understand that the array can be empty.Code snippet that reproduces the problem
https://phpstan.org/r/1dfa2673-c745-4d1b-9492-e50a6ab54eaa
Expected output
No error should be raised.
Did PHPStan help you today? Did it make you happy in any way?
Helps me write working code first time every day.
The text was updated successfully, but these errors were encountered: