Skip to content

Inside foreach, $value is not the same as $array[$key] #6000

@Seldaek

Description

@Seldaek

Bug report

Even though I narrow down which $key is currently being looped over, $value still has an aggregate type of all possible keys, and does not update to become the stricter type associated with just that exact key. Anyway the snippet probably explains this better :D

It may be a feature request more than a bug I suppose.

Code snippet that reproduces the problem

https://phpstan.org/r/456203ce-8c04-406f-b7fb-556ac8d711ca

Expected output

No error

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