Skip to content

Commit 79e4f25

Browse files
committed
add override_static_type_with_self_in_final_class.phpt
1 parent cdaa69e commit 79e4f25

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--TEST--
2+
Overriding static return types with self in final class
3+
--FILE--
4+
<?php
5+
6+
interface A
7+
{
8+
public function method1(): static;
9+
}
10+
11+
abstract class B
12+
{
13+
abstract public function method2(): static;
14+
}
15+
16+
trait C
17+
{
18+
abstract public function method3(): static;
19+
}
20+
21+
final class Foo extends B implements A
22+
{
23+
use C;
24+
25+
public function method1(): self
26+
{
27+
return $this;
28+
}
29+
30+
public function method2(): self
31+
{
32+
return $this;
33+
}
34+
35+
public function method3(): self
36+
{
37+
return $this;
38+
}
39+
}
40+
41+
$foo = new Foo();
42+
43+
var_dump($foo->method1());
44+
var_dump($foo->method2());
45+
var_dump($foo->method3());
46+
?>
47+
--EXPECT--
48+
object(Foo)#1 (0) {
49+
}
50+
object(Foo)#1 (0) {
51+
}
52+
object(Foo)#1 (0) {
53+
}

0 commit comments

Comments
 (0)