Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Weird type of array variable when it is filled in foreach #9332

@lulco

Description

@lulco

Bug report

When filling array in foreach, type of final array is weird - it unions all keys together and also unions all values together so it looks like each key can have any value type, but that's not truth.

Code snippet that reproduces the problem

https://phpstan.org/r/8c25a3d5-2960-47c4-87b8-b86f5b3e4684

Expected output

Type should be something like array{a: 'asdfghi', bd: int<1, 1000>, be: int<1, 1000>, cd: int<1, 1000>, ce: int<1, 1000>} and it should be accepted by array{a: string, bd: int, be: int, cd: int, ce: int}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions