Skip to content

Count after calling SplObjectStorage::removeAll #10884

@hultberg

Description

@hultberg

Bug report

If you call count on a SplObjectStorage before calling SplObjectStorage::removeAll then on subsequent if (count() === 0) calls PHPStan report an error that this check will always be false. Calling removeAll might change the contents. Same problem with removeAllExcept calls.

Strict comparison using === between int<1, max> and 0 will always evaluate to false. 

Code snippet that reproduces the problem

https://phpstan.org/r/69cf4869-d279-4876-977c-468f3f5d94a9

Expected output

No errors

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

PHPStan helps me alot and makes me happy. :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions