Skip to content

Returning from a for loop with empty condition is not recognized #9374

Closed
@martin-heralecky

Description

Bug report

This gives error Function bar() should return string but return statement is missing..

function bar(): string {
    for ($i = 0; ; ++$i)
        return "";
}

Although, using while works as expected.

function bar(): string {
    while (true)
        return "";
}

Code snippet that reproduces the problem

https://phpstan.org/r/4afb0fc0-a96f-44b2-9de1-d112e78f4871

Expected output

No errors.

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

PHPStan is great! ❤️

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions