diff --git a/stubs/arrayFunctions.stub b/stubs/arrayFunctions.stub index 3f98bf62ca..8c438327cd 100644 --- a/stubs/arrayFunctions.stub +++ b/stubs/arrayFunctions.stub @@ -48,3 +48,16 @@ function uksort( array &$one, callable $two ): bool {} + +/** + * @template T of mixed + * + * @param array $one + * @param array $two + * @param callable(T, T): int<-1, 1> $three + */ +function array_udiff( + array $one, + array $two, + callable $three +): int {} diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index c7d2e698e7..338991338d 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -618,6 +618,32 @@ public function testArrayWalkArrowFunctionCallback(): void ]); } + public function testArrayUdiffCallback(): void + { + $this->analyse([__DIR__ . '/data/array_udiff.php'], [ + [ + 'Parameter #3 $data_comp_func of function array_udiff expects callable(int, int): int<-1, 1>, Closure(string, string): string given.', + 6, + ], + [ + 'Parameter #3 $data_comp_func of function array_udiff expects callable(int, int): int<-1, 1>, Closure(int, int): non-empty-string given.', + 14, + ], + [ + 'Parameter #1 $arr1 of function array_udiff expects array, null given.', + 20, + ], + [ + 'Parameter #2 $arr2 of function array_udiff expects array, null given.', + 21, + ], + [ + 'Parameter #3 $data_comp_func of function array_udiff expects callable(string, string): int<-1, 1>, Closure(string, int): non-empty-string given.', + 22, + ], + ]); + } + public function testPregReplaceCallback(): void { $this->analyse([__DIR__ . '/data/preg_replace_callback.php'], [ diff --git a/tests/PHPStan/Rules/Functions/data/array_udiff.php b/tests/PHPStan/Rules/Functions/data/array_udiff.php new file mode 100644 index 0000000000..b3a72cf4d7 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/array_udiff.php @@ -0,0 +1,34 @@ + $b; + }, +); +