phpstan / phpstan

PHP Static Analysis Tool - discover bugs in your code without running it!
https://phpstan.org/
MIT License
12.92k stars 882 forks source link

Parameter #2 $callback of function uasort expects callable(Foo, Foo): int, Closure(string, string): int<-1, 1> given. #11620

Open mxr576 opened 1 month ago

mxr576 commented 1 month ago

Bug report

This should be also an invalid report since uasort() supports sorting of stringable objects as well based on my testing.

https://3v4l.org/hkZjS

Code snippet that reproduces the problem

https://phpstan.org/r/e0e70f12-61aa-412a-9c1b-dcfa097cfa9d

Expected output

No error is reported.

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

No response

mxr576 commented 1 month ago

11619 may or may not be related. The code is the same just strnatcasecmp used differently.

VincentLanglet commented 1 month ago

This is a really special edge case.

See https://3v4l.org/GPV8l

With declare(strict_types = 1);:

You can reproduce the same behavior https://3v4l.org/DHEoB

PHPStan is working like you were using declare(strict_types = 1); in every of your files ; and here, I feel like it's more a "bug" with PHP which doesn't really respects the strict_types directive.

So I would say it's expected.