Skip to content

Union types inside loop don’t apply to the whole loop #9753

@driskell

Description

@driskell

Bug report

It seems that the type of $items is different depending on where in the loop you are - as in it is inferred like it is a run once loop. When actually because it’s a loop the types should be the same throughout.

Definitely terrible code example but a good demonstration.

Code snippet that reproduces the problem

https://phpstan.org/r/32a3c556-8022-4599-a675-e7cc7290e107

Expected output

Clean with no errors

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

I will forever be a happy PHPStan user!

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