Skip to content

false type and value evaluate #5362

@SpacePossum

Description

@SpacePossum

Bug report

Code snippet that reproduces the problem

<?php declare(strict_types = 1);

function foo(int $retry): void {
    echo "\nfoo: ".$retry;
    throw new \Exception();
}

$retry = 2;

do {
    try {
        foo($retry);

        break;
    } catch (\Exception $e) {
        if (0 === $retry) {
            throw $e;
        }

        --$retry;
    }
} while ($retry > 0);

https://phpstan.org/r/da6a9ae4-f4a5-41b7-90f3-5fe8256808d1

12 | Parameter 1 $retry of function foo expects int, int|string given.

I think $retry it always an int

16 | Strict comparison using === between 0 and 2|string will always evaluate to false.

besides the string thingy the value of $retry can be 0,1 and 2 at this line

Expected output

no issues

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

always makes me happy, been a great help in a lot of projects :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions