-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Labels
Description
Bug report
For example, I have the following code:
final class DemoFile
{
private function complementArticleData(Iterator $articles): void
{
$result = [
'artikel' => $articles,
'farben' => null,
'artikel_ids' => [],
];
// collect article ids
foreach ($result['artikel'] as $article) {
$result['artikel_ids'][] = 1;
}
if ($result['artikel_ids'] !== []) {
$result['farben'] = new stdClass();
}
// $result['farben'] might be also null
\PHPStan\dumpType($result['farben']);
if ($result['farben'] instanceof stdClass) {
echo '123';
}
}
}Above, \PHPStan\dumpType($result['farben']); should be null|stdClass, but detected only as stdClass.
Code snippet that reproduces the problem
https://phpstan.org/r/05fd1758-7df0-4307-b419-dc29bd867ae4
Expected output
It should output null|stdClass as type.
Array vs Iterator result:
Array: working OK https://phpstan.org/r/dcded1e7-0941-4d6b-9451-c33face0ff89
Iterator: NOT working https://phpstan.org/r/05fd1758-7df0-4307-b419-dc29bd867ae4
Did PHPStan help you today? Did it make you happy in any way?
No response
Reactions are currently unavailable