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

psalm expects the third parameter of array_udiff() to be an array but it must be a callable #11213

Open
botzkobg opened this issue Jan 28, 2025 · 5 comments
Labels

Comments

@botzkobg
Copy link

botzkobg commented Jan 28, 2025

It seems that psalm expects the third parameter of array_udiff() to be an array but it must be a callable.

Example Code:

<?php

$compare = fn(int $left, int $right): int => $left <=> $right;

$leftArray = [1, 2, 3, 4];
$rightArray = [1, 3, 4, 5];

print_r(array_udiff($leftArray, $rightArray, $compare));

Error message

ERROR: InvalidArgument - src/test.php:8:46 - Argument 3 of array_udiff expects array<array-key, mixed>, but pure-Closure(int, int):(-1|0|1) provided (see https://psalm.dev/004)
print_r(array_udiff($leftArray, $rightArray, $compare));
@botzkobg
Copy link
Author

Link to reproduce: https://psalm.dev/r/9f1b112907

Copy link

I found these snippets:

https://psalm.dev/r/9f1b112907
<?php

$compare = fn(int $left, int $right): int => $left <=> $right;

$leftArray = [1, 2, 3, 4];
$rightArray = [1, 3, 4, 5];

print_r(array_udiff($leftArray, $rightArray, $compare));
Psalm output (using commit a17fdd7):

ERROR: InvalidArgument - 8:46 - Argument 3 of array_udiff expects array<array-key, mixed>, but pure-Closure(int, int):(-1|0|1) provided

@danog danog added the bug label Jan 28, 2025
@danog
Copy link
Collaborator

danog commented Jan 28, 2025

Was super sure there was a parameter type provider for this, will fix...

@botzkobg
Copy link
Author

Thank you @danog.

Just to let you know that while you there you should also fix array_uintersect(). It produces the same error.

Snippet: https://psalm.dev/r/25ab3bae89

Copy link

I found these snippets:

https://psalm.dev/r/25ab3bae89
<?php

$compare = fn(int $left, int $right): int => $left <=> $right;

$leftArray = [1, 2, 3, 4];
$rightArray = [1, 3, 4, 5];

print_r(array_uintersect($leftArray, $rightArray, $compare));
Psalm output (using commit a17fdd7):

ERROR: InvalidArgument - 8:51 - Argument 3 of array_uintersect expects array<array-key, mixed>, but pure-Closure(int, int):(-1|0|1) provided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants