Skip to content

False positive "will always evaluate to false" after array_filter and reset #7928

@rieschl

Description

@rieschl

Bug report

When an array with possible null values is filtered with array_filter and then the first entry is fetched with reset, PHPStan thinks that the array cannot be empty and will emit an error on a === false check.

I tried it on version 1.8.4. 1.8.3 outputs the same error, but 1.8.2 does not.
PHP version 7.4.30

Code snippet that reproduces the problem

https://phpstan.org/r/808dcfd1-17d2-4a54-8cf7-defb3d90dbb1

Expected output

PHPStan should not output an error because reset indeed can return false.

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

PHPStan helps me every time I write some code because it reminds me that there are things to consider I didn't think about 🙂

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions