Skip to content

PHPStan ignores modifying an array by reference #4644

@lulco

Description

@lulco

Bug report

If I'm adding some key to array in foreach (modifying by reference), after this foreach PHPStan doesn't know this new key.

Code snippet that reproduces the problem

https://phpstan.org/r/50a73119-7090-4209-9fd7-4cef743b7760
https://3v4l.org/vDNLo

Expected output

No errors

I tried to initialize that new key in original array with null:
https://phpstan.org/r/d0762209-6772-4a55-9299-e3612f505b28

but error just change to comparing null with null which is not true for first n - 1 elements

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