-
Notifications
You must be signed in to change notification settings - Fork 569
Expand file tree
/
Copy pathbug-11427.php
More file actions
85 lines (72 loc) · 1.53 KB
/
bug-11427.php
File metadata and controls
85 lines (72 loc) · 1.53 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
80
81
82
83
84
85
<?php
namespace Bug11427;
/** @implements \ArrayAccess<int, int> */
class C implements \ArrayAccess {
#[\ReturnTypeWillChange]
public function offsetExists($offset) {
throw new \Exception("exists");
}
#[\ReturnTypeWillChange]
public function offsetGet($offset) {
throw new \Exception("get");
}
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value) {
throw new \Exception("set");
}
#[\ReturnTypeWillChange]
public function offsetUnset($offset) {
throw new \Exception("unset");
}
}
function test(C $c): void {
try {
$x = isset($c[1]);
} catch (\Exception $e) {
// offsetExists can throw
}
try {
$x = $c[1];
} catch (\Exception $e) {
// offsetGet can throw
}
try {
$c[1] = 1;
} catch (\Exception $e) {
// offsetSet can throw
}
try {
unset($c[1]);
} catch (\Exception $e) {
// offsetUnset can throw
}
}
/**
* Union type where isArray() returns maybe and isSuperTypeOf(ArrayAccess) returns maybe.
* This ensures the conditions in NodeScopeResolver are tested with types
* that distinguish !->yes() from ->no() and !->no() from ->yes().
*
* @param array<int, int>|C $c
*/
function testArrayOrArrayAccess($c): void {
try {
$x = isset($c[1]);
} catch (\Exception $e) {
// offsetExists can throw when $c is C
}
try {
$x = $c[1];
} catch (\Exception $e) {
// offsetGet can throw when $c is C
}
try {
$c[1] = 1;
} catch (\Exception $e) {
// offsetSet can throw when $c is C
}
try {
unset($c[1]);
} catch (\Exception $e) {
// offsetUnset can throw when $c is C
}
}