Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gnutix opened this issue Sep 12, 2022 · 1 comment · Fixed by phpstan/phpstan-src#1725

Comments

@gnutix
Copy link

gnutix commented Sep 12, 2022

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?

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

@gnutix gnutix changed the title [>=1.8.3] array_filter does not reduce an array shape's values [>=1.8.3] array_filter does not reduce an array shape's values with a modulo condition Sep 12, 2022
@gnutix gnutix changed the title [>=1.8.3] array_filter does not reduce an array shape's values with a modulo condition [>=1.8.3] array_filter and modulo do not work well together (does not restrict the array's values) Sep 12, 2022
@github-actions
Copy link

github-actions bot commented Oct 15, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant