Skip to content

Intersection for array and ArrayAccess with identical contents always returns mixed #12125

@bitwise-operators

Description

@bitwise-operators

Bug report

When a function or method returns an intersection of array and ArrayAccess with identical key and value types, access to that array will always return mixed, not the specified value type.

Even adding an isset check will only remove null from the possible options, but will still treat the value itself as mixed.

Code snippet that reproduces the problem

https://phpstan.org/r/3739dc63-7633-4d32-a148-098311748c40

Expected output

PHPStan incorrectly throws an error, where none should be.

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

We are working on an old codebase. We've turned PHPstan up to level 10 using a big baseline, and as a way to unwind between regular features and issues, we just delete random rows from the baseline and fix them. Baby-steps toward a better codebase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions