Skip to content

Undesirable error "function should return false/true but returns bool" #4739

@udavka

Description

@udavka

Bug report

An error "Anonymous function should return false but returns bool." occurs when a mix of some operations and comparisons are used. The given example may look strange, but it is a smallest code fragment, which gives the error. Of course, in the real code false and true values are possible, but when PHPStan thinks that the calculated result must be false or true only, it emits an error.

Code snippet that reproduces the problem

https://phpstan.org/r/2b8bcf0b-4486-4b1f-a291-2a61e1431613

Expected output

No errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions