-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Description
Bug report
On PHPStan level 9
When using isset($data['foo']) with $data being mixed, PHPStan complains about "Cannot access offset 'foo' on mixed.".
Also, when checking for value type, like is_string($json['Foo']['Bar']), the value type is not narrowed.
Code snippet that reproduces the problem
public function sayHello(mixed $json): string
{
if (!isset($json['Foo']['Bar']) || !is_string($json['Foo']['Bar'])) {
throw new \Exception('Bad JSON');
}
return $json['Foo']['Bar'];
}https://phpstan.org/r/9b18a65f-f28d-4374-8167-1e94703d9707
Expected output
PHPStan should not report an issue when trying to access offset inside isset, and after validating offset with isset, we should be able to assert the type
Did PHPStan help you today? Did it make you happy in any way?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels