Skip to content

False positive  #10644

@jrbasso

Description

@jrbasso

Bug report

When the code is throwing an exception when the value is not of a certain type, the code using the array content is still assuming the type is mixed.

In the code snippet, the $data can contain the key subtitle, which, when present, is mixed. The code is checking if the key exists and throwing an exception if not an string. So the only way to pass that step is if $data['substitle'] is either not set or a string. When assigning it to a string property with a null coalescing operator, it guarantees the value is always a string. PHPStan still thinking the value is a mixed.

Code snippet that reproduces the problem

https://phpstan.org/r/977a50c8-67f1-4f2c-8b49-e9b3189345ad

Expected output

PHPStan shouldn't detect an error since the code was already throwing an exception if the value is not a string.

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions