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

array_udiff() comparator type is too strict #9697

Closed
stefanfisk opened this issue Jul 29, 2023 · 3 comments
Closed

array_udiff() comparator type is too strict #9697

stefanfisk opened this issue Jul 29, 2023 · 3 comments
Labels
Milestone

Comments

@stefanfisk
Copy link

Bug report

array_udiff() comparators should return an integer less than, equal to, or greater than zero according to the docs, but PHPStan raises an issue if the comparator's return type is not int<-1,1>.

usort() does however accept any int.

Code snippet that reproduces the problem

https://phpstan.org/r/a036787e-1397-49a1-9391-891f4332df5b

Expected output

There should be no issues.

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

It helped me catch a case where not all code paths returned a value!

@stefanfisk stefanfisk changed the title array_udiff() comparator array_udiff() comparator type is too strict Jul 29, 2023
@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Aug 7, 2023
@phpstan-bot
Copy link
Contributor

@stefanfisk After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
 PHP 7.4 – 8.3 (1 error)
 ==========
 
-13: Parameter #3 $data_comp_func of function array_udiff expects callable(int, int): int<-1, 1>, Closure(int, int): int given.
+13: Parameter #3 $data_comp_func of function array_udiff expects callable(1|2|3, 1|2|3): int<-1, 1>, Closure(int, int): int given.
 
 PHP 7.2 – 7.3 (1 error)
 ==========
 
  6: Syntax error, unexpected T_VARIABLE, expecting ')' on line 6
Full report

PHP 7.4 – 8.3 (1 error)

Line Error
13 `Parameter #3 $data_comp_func of function array_udiff expects callable(1

PHP 7.2 – 7.3 (1 error)

Line Error
6 Syntax error, unexpected T_VARIABLE, expecting ')' on line 6

@ondrejmirtes
Copy link
Member

Fixed phpstan/phpstan-src#2822

Copy link

github-actions bot commented Feb 6, 2024

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 Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants