Skip to content

False array type specification adding foreach #7144

@rajyan

Description

@rajyan

Bug report

Another related issue for #7000
Adding foreach make a wrong assumption on array type.

Code snippet that reproduces the problem

https://phpstan.org/r/f2f27d58-21fa-480c-a284-d70777f19926

The problem is described in test3. The addition of key in line 30 (compared to test1) and addition of foreach in line 32 (compared to test2) makes the type of $arr as array<'bar'|'baz'|'foo', array<string>> which I think is not correct.

Expected output

Addition of foreach should not change the array type.
Also, it should report on line 32 for non existing offset access.

Did PHPStan help you today? Did it make you happy in any way?

Yes! 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    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