Skip to content

array_key_exists narrows $key too much #11724

@staabm

Description

@staabm

Bug report

while working on phpstan/phpstan-src#3453 (comment) I realized that the current $key narrowing for array_key_exists is buggy, as it assumes the key can only be int|string but because of casting rules it could be string|int|float|bool|null

see e.g. https://3v4l.org/oZVkJ

Code snippet that reproduces the problem

https://phpstan.org/r/0172cf80-e0d8-4cb5-acef-5f4884b3bd5b

Expected output

a type like mixed~(array|object) for everything which is a string but non-numeric

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

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions