-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathbug-10396.php
More file actions
79 lines (72 loc) · 1.69 KB
/
bug-10396.php
File metadata and controls
79 lines (72 loc) · 1.69 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php // lint >= 7.4
namespace Bug10396;
use function PHPStan\Testing\assertType;
// preg_replace_callback_array - without flags
function testCallbackArrayNoFlags(string $s): void {
preg_replace_callback_array(
[
'/(foo)(bar)/' => function ($matches) {
assertType("mixed", $matches); // no flags, no attribute set
return '';
},
],
$s
);
}
// preg_replace_callback_array with PREG_UNMATCHED_AS_NULL
function testCallbackArrayUnmatchedAsNull(string $s): void {
preg_replace_callback_array(
[
'/(foo)?(bar)/' => function ($matches) {
assertType("array<int|string, string|null>", $matches);
return '';
},
],
$s,
-1,
$count,
PREG_UNMATCHED_AS_NULL
);
}
// preg_replace_callback_array with PREG_OFFSET_CAPTURE
function testCallbackArrayOffsetCapture(string $s): void {
preg_replace_callback_array(
[
'/(foo)(bar)/' => function ($matches) {
assertType("array<int|string, array{string, int<-1, max>}>", $matches);
return '';
},
],
$s,
-1,
$count,
PREG_OFFSET_CAPTURE
);
}
// preg_replace_callback_array with both flags
function testCallbackArrayBothFlags(string $s): void {
preg_replace_callback_array(
[
'/(foo)?(bar)/' => function ($matches) {
assertType("array<int|string, array{string|null, int<-1, max>}>", $matches);
return '';
},
],
$s,
-1,
$count,
PREG_OFFSET_CAPTURE | PREG_UNMATCHED_AS_NULL
);
}
// preg_replace_callback_array with arrow function
function testCallbackArrayArrowFunction(string $s): void {
preg_replace_callback_array(
[
'/(foo)(bar)/' => fn ($matches) => assertType("array<int|string, array{string, int<-1, max>}>", $matches) ? '' : '',
],
$s,
-1,
$count,
PREG_OFFSET_CAPTURE
);
}