Skip to content

Commit 7fe477d

Browse files
author
michael19
committed
#17725 add more tests
1 parent ceb8396 commit 7fe477d

File tree

3 files changed

+191
-0
lines changed

3 files changed

+191
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Overriding another one type in final class with union types
3+
--FILE--
4+
<?php
5+
6+
interface A
7+
{
8+
public function methodScalar1(): static|bool;
9+
}
10+
11+
final class B implements A
12+
{
13+
public function methodScalar1(): array { return []; }
14+
}
15+
16+
$b = new B();
17+
var_dump($b->methodScalar1());
18+
?>
19+
--EXPECTF--
20+
Fatal error: Declaration of B::methodScalar1(): array must be compatible with A::methodScalar1(): static|bool in %s on line %d
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Overriding another one type in final class with union types
3+
--FILE--
4+
<?php
5+
6+
interface A
7+
{
8+
public function methodScalar1(): static|bool;
9+
}
10+
11+
final class B implements A
12+
{
13+
public function methodScalar1(): self|array { return []; }
14+
}
15+
16+
$b = new B();
17+
var_dump($b->methodScalar1());
18+
?>
19+
--EXPECTF--
20+
Fatal error: Declaration of B::methodScalar1(): array must be compatible with A::methodScalar1(): static|bool in %s on line %d
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
--TEST--
2+
Overriding static return types with self in final class with union types
3+
--FILE--
4+
<?php
5+
6+
interface A
7+
{
8+
public function methodScalar1(): static|bool;
9+
public function methodScalar2(): static|bool;
10+
public function methodScalar3(): static|false;
11+
public function methodScalar4(): static|true;
12+
public function methodScalar5(): static|bool;
13+
public function methodScalar6(): static|bool;
14+
public function methodScalar7(): static|string;
15+
public function methodScalar8(): static|string;
16+
public function methodScalar9(): static|string;
17+
public function methodScalar10(): static|int;
18+
public function methodScalar11(): static|int;
19+
public function methodScalar12(): static|int;
20+
public function methodScalar13(): static|float;
21+
public function methodScalar14(): static|float;
22+
public function methodScalar15(): static|float;
23+
public function methodIterable1(): static|iterable;
24+
public function methodIterable2(): static|iterable;
25+
public function methodIterable3(): static|array;
26+
public function methodObject1(): static|A;
27+
public function methodObject2(): static|B;
28+
public function methodObject3(): static|C;
29+
public function methodObject4(): static|self;
30+
public function methodObject5(): static|self;
31+
public function methodNullable1(): ?static;
32+
public function methodNullable2(): ?static;
33+
public function methodNullable3(): static|null;
34+
public function methodNullable4(): static|null;
35+
public function methodNullable5(): null;
36+
}
37+
38+
final class B implements A
39+
{
40+
public function methodScalar1(): self|false { return $this; }
41+
public function methodScalar2(): self|true { return $this; }
42+
public function methodScalar3(): false { return false; }
43+
public function methodScalar4(): true { return true; }
44+
public function methodScalar5(): bool { return false; }
45+
public function methodScalar6(): self { return $this; }
46+
public function methodScalar7(): self|string { return $this; }
47+
public function methodScalar8(): string { return ''; }
48+
public function methodScalar9(): self { return $this; }
49+
public function methodScalar10(): self|int { return $this; }
50+
public function methodScalar11(): int { return 0; }
51+
public function methodScalar12(): self { return $this; }
52+
public function methodScalar13(): self|float { return $this; }
53+
public function methodScalar14(): float { return 0.0; }
54+
public function methodScalar15(): self { return $this; }
55+
public function methodIterable1(): self|iterable { return $this; }
56+
public function methodIterable2(): self|array { return $this; }
57+
public function methodIterable3(): array { return []; }
58+
public function methodObject1(): self { return $this; }
59+
public function methodObject2(): B { return $this; }
60+
public function methodObject3(): C { return new C(); }
61+
public function methodObject4(): self { return $this; }
62+
public function methodObject5(): B { return $this; }
63+
public function methodNullable1(): ?static { return $this; }
64+
public function methodNullable2(): ?static { return null; }
65+
public function methodNullable3(): static|null { return null; }
66+
public function methodNullable4(): static|null { return $this; }
67+
public function methodNullable5(): null { return null; }
68+
}
69+
70+
class C
71+
{
72+
}
73+
74+
$b = new B();
75+
var_dump($b->methodScalar1());
76+
var_dump($b->methodScalar2());
77+
var_dump($b->methodScalar3());
78+
var_dump($b->methodScalar4());
79+
var_dump($b->methodScalar5());
80+
var_dump($b->methodScalar6());
81+
var_dump($b->methodScalar7());
82+
var_dump($b->methodScalar8());
83+
var_dump($b->methodScalar9());
84+
var_dump($b->methodScalar10());
85+
var_dump($b->methodScalar11());
86+
var_dump($b->methodScalar12());
87+
var_dump($b->methodScalar13());
88+
var_dump($b->methodScalar14());
89+
var_dump($b->methodScalar15());
90+
var_dump($b->methodIterable1());
91+
var_dump($b->methodIterable2());
92+
var_dump($b->methodIterable3());
93+
var_dump($b->methodObject1());
94+
var_dump($b->methodObject2());
95+
var_dump($b->methodObject3());
96+
var_dump($b->methodObject4());
97+
var_dump($b->methodObject5());
98+
var_dump($b->methodNullable1());
99+
var_dump($b->methodNullable2());
100+
var_dump($b->methodNullable3());
101+
var_dump($b->methodNullable4());
102+
var_dump($b->methodNullable5());
103+
?>
104+
--EXPECTF--
105+
object(B)#1 (0) {
106+
}
107+
object(B)#1 (0) {
108+
}
109+
bool(false)
110+
bool(true)
111+
bool(false)
112+
object(B)#1 (0) {
113+
}
114+
object(B)#1 (0) {
115+
}
116+
string(0) ""
117+
object(B)#1 (0) {
118+
}
119+
object(B)#1 (0) {
120+
}
121+
int(0)
122+
object(B)#1 (0) {
123+
}
124+
object(B)#1 (0) {
125+
}
126+
float(0)
127+
object(B)#1 (0) {
128+
}
129+
object(B)#1 (0) {
130+
}
131+
object(B)#1 (0) {
132+
}
133+
array(0) {
134+
}
135+
object(B)#1 (0) {
136+
}
137+
object(B)#1 (0) {
138+
}
139+
object(C)#2 (0) {
140+
}
141+
object(B)#1 (0) {
142+
}
143+
object(B)#1 (0) {
144+
}
145+
object(B)#1 (0) {
146+
}
147+
NULL
148+
NULL
149+
object(B)#1 (0) {
150+
}
151+
NULL

0 commit comments

Comments
 (0)