Skip to content

Commit 31c53e4

Browse files
committed
#17725 add more tests for union types
1 parent 6b3ca17 commit 31c53e4

8 files changed

+196
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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(): C|array { return []; }
14+
}
15+
16+
class C
17+
{
18+
}
19+
20+
$b = new B();
21+
var_dump($b->methodScalar1());
22+
?>
23+
--EXPECTF--
24+
Fatal error: Declaration of B::methodScalar1(): C|array must be compatible with A::methodScalar1(): static|bool in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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(): C { return new C(); }
14+
}
15+
16+
final class C implements A
17+
{
18+
public function methodScalar1(): self { return $this; }
19+
}
20+
21+
$b = new B();
22+
var_dump($b->methodScalar1());
23+
?>
24+
--EXPECTF--
25+
Fatal error: Declaration of B::methodScalar1(): C must be compatible with A::methodScalar1(): static|bool in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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(): C|array { return []; }
14+
}
15+
16+
final class C implements A
17+
{
18+
public function methodScalar1(): self { return $this; }
19+
}
20+
21+
$b = new B();
22+
var_dump($b->methodScalar1());
23+
?>
24+
--EXPECTF--
25+
Fatal error: Declaration of B::methodScalar1(): C|array must be compatible with A::methodScalar1(): static|bool in %s on line %d
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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(): C { return new C(); }
14+
}
15+
16+
final class C
17+
{
18+
}
19+
20+
$b = new B();
21+
var_dump($b->methodScalar1());
22+
?>
23+
--EXPECTF--
24+
Fatal error: Declaration of B::methodScalar1(): C must be compatible with A::methodScalar1(): static|bool in %s on line %d
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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(): C|array { return []; }
14+
}
15+
16+
final class C
17+
{
18+
}
19+
20+
$b = new B();
21+
var_dump($b->methodScalar1());
22+
?>
23+
--EXPECTF--
24+
Fatal error: Declaration of B::methodScalar1(): C|array must be compatible with A::methodScalar1(): static|bool in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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(): C { return new C(); }
14+
}
15+
16+
class C implements A
17+
{
18+
public function methodScalar1(): static { return $this; }
19+
}
20+
21+
$b = new B();
22+
var_dump($b->methodScalar1());
23+
?>
24+
--EXPECTF--
25+
Fatal error: Declaration of B::methodScalar1(): C must be compatible with A::methodScalar1(): static|bool in %s on line %d
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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(): C|array { return []; }
14+
}
15+
16+
class C implements A
17+
{
18+
public function methodScalar1(): static { return $this; }
19+
}
20+
21+
$b = new B();
22+
var_dump($b->methodScalar1());
23+
?>
24+
--EXPECTF--
25+
Fatal error: Declaration of B::methodScalar1(): C|array must be compatible with A::methodScalar1(): static|bool in %s on line %d
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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(): C { return new C(); }
14+
}
15+
16+
class C
17+
{
18+
}
19+
20+
$b = new B();
21+
var_dump($b->methodScalar1());
22+
?>
23+
--EXPECTF--
24+
Fatal error: Declaration of B::methodScalar1(): C must be compatible with A::methodScalar1(): static|bool in %s on line %d

0 commit comments

Comments
 (0)