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
PHP8 usort with version_compare as callback #6492
Comments
version_compare returns |
Okay it returns bool if the third parameter operator is defined, which is not the case using the function the way mentioned.
|
Until this is supported you can use the arrow function version, thanks. |
@herndlm this is another issue which would benefit from a AST rewrite into a arrow function like phpstan/phpstan-src#938 wdyt? :) |
That’s not needed, it’s just that dynamic return type extension needs to be invoked for cases like this. |
Not ideal, but works with PHP 7.4 and 8.1 at the same time: /** @var callable(string $a, string $b): int $comparer */
$comparer = 'version_compare';
usort($versions, $comparer); |
Bug report
Using
\usort
with an PHP core function(version_compare
) reports an error in PHP8.Parameter #2 $callback of function usort expects callable(string, string): int, 'version_compare' given.
Code snippet that reproduces the problem
https://phpstan.org/r/e27b69c8-d3df-4347-b251-de8aa66a89a2
Expected output
No error
The text was updated successfully, but these errors were encountered: