-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Expand file tree
/
Copy pathintersection_types.phpt
More file actions
80 lines (71 loc) · 1.58 KB
/
Copy pathintersection_types.phpt
File metadata and controls
80 lines (71 loc) · 1.58 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
--TEST--
Intersection types in reflection
--FILE--
<?php
function dumpType(ReflectionIntersectionType $rt) {
echo "Type $rt:\n";
echo "Allows null: " . json_encode($rt->allowsNull()) . "\n";
foreach ($rt->getTypes() as $type) {
echo " Name: " . $type->getName() . "\n";
echo " String: " . (string) $type . "\n";
echo " Allows Null: " . json_encode($type->allowsNull()) . "\n";
}
}
function test1(): X&Y&Z&Traversable&Countable { }
class Test {
public X&Y&Countable $prop;
}
dumpType((new ReflectionFunction('test1'))->getReturnType());
$rc = new ReflectionClass(Test::class);
$rp = $rc->getProperty('prop');
dumpType($rp->getType());
/* Force CE resolution of the property type */
interface y {}
class x implements Y, Countable {
public function count(): int { return 0; }
}
$test = new Test;
$test->prop = new x;
$rp = $rc->getProperty('prop');
dumpType($rp->getType());
?>
--EXPECT--
Type X&Y&Z&Traversable&Countable:
Allows null: false
Name: X
String: X
Allows Null: false
Name: Y
String: Y
Allows Null: false
Name: Z
String: Z
Allows Null: false
Name: Traversable
String: Traversable
Allows Null: false
Name: Countable
String: Countable
Allows Null: false
Type X&Y&Countable:
Allows null: false
Name: X
String: X
Allows Null: false
Name: Y
String: Y
Allows Null: false
Name: Countable
String: Countable
Allows Null: false
Type X&Y&Countable:
Allows null: false
Name: X
String: X
Allows Null: false
Name: Y
String: Y
Allows Null: false
Name: Countable
String: Countable
Allows Null: false