-
-
Notifications
You must be signed in to change notification settings - Fork 947
wrongly reporting error on non existing array keys #6783
Copy link
Copy link
Closed
phpstan/phpstan-src
#1657Labels
Milestone
Description
Bug report
PPHStan is reporting error on non existing array keys.
Code snippet that reproduces the problem
<?php declare(strict_types = 1);
/**
* @return array<string, mixed>
*/
function foo(): array
{
// something from elsewhere (not in the scope of PHPStan)
return [
// removing or keeping those lines does/should not change the reporting
'foo' => [
'bar' => true,
]
];
}
$data = foo();
$data = $data['foo'] ?? []; // <<< removing this line suppress the error
$data += [
'default' => true,
];
foreach (['formatted'] as $field) {
$data[$field] = empty($data[$field]) ? false : true;
}
$bar = $data['bar'];https://phpstan.org/r/f765334e-f883-4721-a742-7ea798cf9d4c
Expected output
No error
Reactions are currently unavailable