Skip to content

Accessing an array with non array-key type should be an error #13135

@azjezz

Description

@azjezz

Bug report

When accessing an array either for reading or writing, the index type MUST be a sub-type of array-key.

PHPStan seems to allow generics that do not have an array-key constraint.

This is a problem because it gives a false sense of safety, as it could lead to type errors at runtime: https://3v4l.org/u0tJV

Code snippet that reproduces the problem

https://phpstan.org/r/4dfc8a86-b078-4a82-b675-93b250a4ef1a

Expected output

Error: Attempting to access an array index using Tk, expected a sub-type of array-key

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

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions