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

Skip to content

Refining array type in loops only works for the first iteration #13643

@uuf6429

Description

@uuf6429

Bug report

Consider the following code, where the warnings makes sense (because only 'aaa' is checked):
https://phpstan.org/r/2a53ae2b-77a7-4948-bb24-22c0d96a6762 (example 1)

When more than one index is checked, it stops working entirely:
https://phpstan.org/r/a023dad0-48d0-4b6c-a2ac-1f32dc5e65f4 (example 2)

I also tried with inverting the inner if condition and putting continue - it didn't help:
https://phpstan.org/r/f4e936e5-0b3e-4d64-afcb-8f256a7b0826 (example 3)

Code snippet that reproduces the problem

No response

Expected output

Example 1 is correct, but examples 2 and 3 should not produce any warnings.

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

No response

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