Skip to content

False positive with array_key_exists and union types #13526

@philipheimboeck

Description

@philipheimboeck

Bug report

Hello,
I've ran into an issue in some legacy project after upgrading to version 2.1.25.
Basically there are two maps and one of them is used dynamically. PHPStan seems to make a union type out of it in the background (judging by the error message).

Although array_key_exists returns true, it still reports an error, that the key might not exist in one of the two maps.

Code snippet that reproduces the problem

https://phpstan.org/r/4c05958a-eefb-4335-b210-8680b9edfae1

Expected output

As it is a false positive, no error should be reported.

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

Thanks for all the hard work! PHPStan helped us a lot in finding bugs early especially when working with legacy code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions