PHPStan not determining correct return type with array_diff_keys() · Issue #14862 · phpstan/phpstan · GitHub
Skip to content

PHPStan not determining correct return type with array_diff_keys() #14862

Description

@cviebrock

Bug report

I think there is an issue with how PHPstan determines array shapes (even with bleeding edge on in 2.2) when code uses array_diff_keys and/or array_flip to remove keys from an input array.

\PHPStan\dumpType() shows exactly what I think it should in the example below, although it still finds an error when analyzing the code.

Code snippet that reproduces the problem

https://phpstan.org/r/d9895bff-575a-4f8f-bf31-9fb2d88d3425

Expected output

The only output from the above should be from dumpType(). The other reported error in the code about the returned array's shape should not be reported.

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

We've cleaned up so much of our legacy code base thanks to PHPStan ... thank you for your work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions