Skip to content

Commit 97ce9f2

Browse files
phpstan-botclaude
andcommitted
Add tests for userland comparators with uasort/usort
When a builtin function like uasort calls a userland callback, it's always treated as strict_types=0, so Stringable objects are accepted for string parameters. Added test cases for both strict and non-strict mode to verify no false positives. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cefb24b commit 97ce9f2

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2761,7 +2761,7 @@ public function testBug11619Strict(): void
27612761
],
27622762
[
27632763
'Parameter #2 $f of function Bug11619Strict\customUsort expects callable(Stringable, Stringable): int, \'strnatcasecmp\' given.',
2764-
54,
2764+
58,
27652765
],
27662766
]);
27672767
}

tests/PHPStan/Rules/Functions/data/bug-11619-strict.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ function customUsort(array &$a, callable $f): void
4343
[$a[$j-1], $a[$j]] = [$a[$j], $a[$j-1]];
4444
}
4545

46+
function userlandComparator(string $a, string $b): int {
47+
return strnatcasecmp($a, $b);
48+
}
49+
4650
function test2(): void
4751
{
4852
$options = [
@@ -52,4 +56,7 @@ function test2(): void
5256
];
5357

5458
customUsort($options, 'strnatcasecmp');
59+
60+
uasort($options, 'Bug11619Strict\userlandComparator');
61+
usort($options, 'Bug11619Strict\userlandComparator');
5562
}

tests/PHPStan/Rules/Functions/data/bug-11619.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ function customUsort(array &$a, callable $f): void
4343
[$a[$j-1], $a[$j]] = [$a[$j], $a[$j-1]];
4444
}
4545

46+
function userlandComparator(string $a, string $b): int {
47+
return strnatcasecmp($a, $b);
48+
}
49+
4650
function test2(): void
4751
{
4852
$options = [
@@ -52,4 +56,7 @@ function test2(): void
5256
];
5357

5458
customUsort($options, 'strnatcasecmp');
59+
60+
uasort($options, 'Bug11619\userlandComparator');
61+
usort($options, 'Bug11619\userlandComparator');
5562
}

0 commit comments

Comments
 (0)