Skip to content

Commit 12bfa65

Browse files
committed
Add return type test
1 parent bfc3e45 commit 12bfa65

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
--TEST--
2+
Partial application: relative return types
3+
--FILE--
4+
<?php
5+
6+
if (time() > 0) {
7+
trait T {
8+
public function getSelf(object $o): self {
9+
return $o;
10+
}
11+
public function getStatic(object $o): static {
12+
return $o;
13+
}
14+
}
15+
}
16+
17+
class C {
18+
use T;
19+
}
20+
21+
class D extends C {
22+
}
23+
24+
$c = new C;
25+
26+
$self = $c->getSelf(?);
27+
28+
echo (string) new ReflectionFunction($self), "\n";
29+
30+
var_dump($self($c));
31+
var_dump($self(new D));
32+
try {
33+
$self(new stdClass);
34+
} catch (Error $e) {
35+
echo $e->getMessage(), "\n";
36+
}
37+
38+
$static = $c->getStatic(?);
39+
40+
echo (string) new ReflectionFunction($static), "\n";
41+
42+
var_dump($static($c));
43+
var_dump($static(new D));
44+
try {
45+
$static(new stdClass);
46+
} catch (Error $e) {
47+
echo $e->getMessage(), "\n";
48+
}
49+
50+
$d = new D;
51+
52+
$self = $d->getSelf(?);
53+
54+
echo (string) new ReflectionFunction($self), "\n";
55+
56+
var_dump($self($d));
57+
var_dump($self(new D));
58+
try {
59+
$self(new stdClass);
60+
} catch (Error $e) {
61+
echo $e->getMessage(), "\n";
62+
}
63+
64+
$static = $d->getStatic(?);
65+
66+
echo (string) new ReflectionFunction($static), "\n";
67+
68+
var_dump($static($d));
69+
var_dump($static(new D));
70+
try {
71+
$static(new stdClass);
72+
} catch (Error $e) {
73+
echo $e->getMessage(), "\n";
74+
}
75+
76+
?>
77+
--EXPECTF--
78+
Partial [ <user, prototype C> public method getSelf ] {
79+
@@ %s.php 23 - 23
80+
81+
- Parameters [1] {
82+
Parameter #0 [ <required> object $o ]
83+
}
84+
- Return [ self ]
85+
}
86+
87+
object(C)#%d (0) {
88+
}
89+
object(D)#%d (0) {
90+
}
91+
C::getSelf(): Return value must be of type C, stdClass returned
92+
Partial [ <user, prototype C> public method getStatic ] {
93+
@@ %s.php 35 - 35
94+
95+
- Parameters [1] {
96+
Parameter #0 [ <required> object $o ]
97+
}
98+
- Return [ static ]
99+
}
100+
101+
object(C)#%d (0) {
102+
}
103+
object(D)#%d (0) {
104+
}
105+
C::getStatic(): Return value must be of type C, stdClass returned
106+
Partial [ <user, prototype C> public method getSelf ] {
107+
@@ %s.php 49 - 49
108+
109+
- Parameters [1] {
110+
Parameter #0 [ <required> object $o ]
111+
}
112+
- Return [ self ]
113+
}
114+
115+
object(D)#%d (0) {
116+
}
117+
object(D)#%d (0) {
118+
}
119+
C::getSelf(): Return value must be of type C, stdClass returned
120+
Partial [ <user, prototype C> public method getStatic ] {
121+
@@ %s.php 61 - 61
122+
123+
- Parameters [1] {
124+
Parameter #0 [ <required> object $o ]
125+
}
126+
- Return [ static ]
127+
}
128+
129+
object(D)#%d (0) {
130+
}
131+
object(D)#%d (0) {
132+
}
133+
C::getStatic(): Return value must be of type D, stdClass returned

0 commit comments

Comments
 (0)