Skip to content

Add check for autoconversion of numeric string to int when used as array key #1770

@meridius

Description

@meridius

Summary of a problem or a feature request

It is a known gotcha, that PHP silently converts numeric strings to integers when they are used as keys in an array. This is a serious problem in strictly typed code, since PHP will fail on Fatal error: Uncaught TypeError.

Code snippet that reproduces the problem

https://phpstan.org/r/47f7b660-ca6d-425e-898a-58d8a53cda85

Expected output

PhpStan should find these possible errors and report them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions