Skip to content

[>=1.8.3] array_filter and modulo do not work well together (does not restrict the array's values) #7993

@gnutix

Description

@gnutix

Bug report

Since upgrading from 1.8.2 to 1.8.5, I've got the following inspection coming up in a test :

Call to static method PHPUnit\Framework\Assert::assertSame() with array{2, 4} and array{1, 2, 3, 4, 5} will always evaluate to false.

I've reproduced it below in the playground without PHPUnit in the mix. It seems like the modulo is too hard for PHPStan to deal with, as replacing the condition by 2 === $value || 4 === $value returns the proper type.

Code snippet that reproduces the problem

https://phpstan.org/r/1c5d7559-1568-4b26-a45b-f56317935ad2

Expected output

The output should be array{1: 2, 3: 4}.

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

❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️

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