Skip to content

False positive type error on key when changing associative array key in a foreach loop #4612

@binary-data

Description

@binary-data

Bug report

PHPStan somehow infers int|string type when the associative array is explicitly marked with <int, int> type and reports an error in a foreach loop with $key => $value.

Error disappears after removing $array[$prev] = $v; line.

Code snippet that reproduces the problem

https://phpstan.org/r/9e3f4300-ee94-4f03-98cf-cc5cfa329f15

Expected output

Should be no error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions