Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

false type and value evaluate #5362

Closed
SpacePossum opened this issue Jul 22, 2021 · 6 comments
Closed

false type and value evaluate #5362

SpacePossum opened this issue Jul 22, 2021 · 6 comments
Labels
Milestone

Comments

@SpacePossum
Copy link

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 :)

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jul 22, 2021
@phpstan-bot
Copy link
Contributor

@SpacePossum After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
 12: Parameter #1 $retry of function foo expects int, int|string given.
+14: Keyword break used outside of a loop or a switch statement.
 16: Strict comparison using === between 0 and 2|string will always evaluate to false.
Full report
Line Error
12 `Parameter #1 $retry of function foo expects int, int
14 Keyword break used outside of a loop or a switch statement.
16 `Strict comparison using === between 0 and 2

@SpacePossum
Copy link
Author

thank you bot, that shows a new problem 😅

@ondrejmirtes
Copy link
Member

Sorry, there was a bug in the playground.

@SpacePossum
Copy link
Author

no worries at all man :) thanks for all the great work!

@phpstan-bot
Copy link
Contributor

@SpacePossum After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-12: Parameter #1 $retry of function foo expects int, int|string given.
-16: Strict comparison using === between 0 and 2|string will always evaluate to false.
+16: Strict comparison using === between 0 and 1|2 will always evaluate to false.
Full report
Line Error
16 `Strict comparison using === between 0 and 1

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants