Skip to content

string is incorrectly narrowed down in if with and + or conditions #6329

@herndlm

Description

@herndlm

Bug report

PHPStan seems to be having problems narrowing down types in more complex if statements. In the case I added I use is_string and checks against null and '' to determine that this is a non-empty-string|null type. In a case it is wrongfully detected as string|null though. The example makes more sense than me here I guess :)

Could just be a limitation of PHPStan's capabilities with ifs, feel free to close then.

Code snippet that reproduces the problem

https://phpstan.org/r/ae139617-651e-4a89-8e13-824f9ce1a511

Expected output

No errors

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

Always :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions