Skip to content

Value of a variable is forgotten in case where it ought to be known with certainty #11705

@mind-bending-forks

Description

@mind-bending-forks

Bug report

I have encountered a scenario where the value of a variable appears to be 'forgotten' by phpstan in a case where it ought to be known with certainty, and as a result, phpstan fails to narrow a type and so reports an incorrect error.

Code snippet that reproduces the problem

https://phpstan.org/r/f1aad144-7261-4e0b-ac2c-bba065431bcb

Expected output

No error reported by phpstan.

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

Phpstan doesn't eliminate the need for testing to check that the code does what it is supposed to do, of course, but the code becomes more precisely specified and so dependable, which makes it easier to maintain. Developing or working with a code base that has been raised to a high phpstan strictness level is a pleasure, since phpstan will quickly warn you if you attempt to make a change of dubious quality. Very happy about this!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions