Skip to content

assert does not constrain to string union to evaluate accessed value type under array key #4747

@simPod

Description

@simPod

Bug report

asserting $var to be of value 'x' does not help phpstan to understand that $a['a'.$var] accesses $a['ax'].

So for $a = array{ax: int, ay: string}, phpstan does not know $a['a'.$var] is of type int (thinks int|string instead).

Code snippet that reproduces the problem

https://phpstan.org/r/75bd8b4b-f09b-40e9-82f4-6083cc22cb10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions