forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-11619.php
More file actions
55 lines (43 loc) · 1.05 KB
/
bug-11619.php
File metadata and controls
55 lines (43 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php // lint >= 8.1
namespace Bug11619;
final class Foo implements \Stringable {
private function __construct(public readonly string $value) {
}
public static function fromString(string $string): self {
return new self($string);
}
public function __toString(): string {
return $this->value;
}
}
function test(): void
{
$options = [
Foo::fromString('c'),
Foo::fromString('b'),
Foo::fromString('a'),
];
uasort($options, 'strnatcasecmp');
usort($options, 'strnatcasecmp');
uasort($options, fn($a, $b) => strnatcasecmp($a, $b));
uasort($options, fn(string $a, string $b) => strnatcasecmp($a, $b));
}
/**
* @param array<\Stringable> $a
* @param callable(\Stringable, \Stringable): int $f
*/
function customUsort(array &$a, callable $f): void
{
for ($i = 1; $i < count($a); $i++)
for ($j = $i; $j > 0 && $f($a[$j-1], $a[$j]) > 0; $j--)
[$a[$j-1], $a[$j]] = [$a[$j], $a[$j-1]];
}
function test2(): void
{
$options = [
Foo::fromString('c'),
Foo::fromString('b'),
Foo::fromString('a'),
];
customUsort($options, 'strnatcasecmp');
}