Skip to content

Inconsistent array key  #12413

@devnix

Description

@devnix

Bug report

Hi! I think I've found some inconsistencies in handling string array keys and the implicit cast.

Code snippet that reproduces the problem

https://phpstan.org/r/61624d33-5c41-43bf-a44f-357ef10575b5

Expected output

Some of my thoughts:

  • string should be considered as int|string
    • Maybe there should be some enforcements asking for a non-numeric string.
  • numeric-string should not be considered int, but int|string too. Maybe some more specific types (int-string|float-string/numeric-string-int|numeric-string-float/numeric-string<int|float>?) would help but I don't know if it would be worth.
  • Edit: even a numeric-string<int> would still not be casted to int anyway, if it starts with 0

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

Oh boy do I love it

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