Skip to content

String offsets are always considered invalid if they aren't strictly int #3803

@dktapps

Description

@dktapps

Bug report

I stumbled across this while working on phpstan/phpstan-src#311.

In the test sample below, the given array may have legal keys, but PHPStan doesn't think so. Without phpstan/phpstan-src#311, this results in erroneous coercion into array; with it, it results in the string remaining unchanged.

Code snippet that reproduces the problem

https://phpstan.org/r/ed1af86c-a6b8-4b4c-9824-11c720e01b90
https://3v4l.org/fsv1d

Expected output

No error should be reported on line 9.

Possibly, an error could be reported on line 7, because $k is not guaranteed to be an int; however, I think this might go against the idea of BenevolentUnionType so I'm not sure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions