1<?php
2
3// Requires X, delay to runtime.
4// TODO: It is not actually required, because we don't need X to check inheritance in this case.
5class A extends Z {
6    public function method(X $a) {}
7}
8class B extends Z {
9    public function method($a) : X {}
10}
11
12// Works.
13class C extends Z {
14    public function method($a): self {}
15    public function method2($a): C {}
16    public function method3($a): object {}
17    public function method4(D $a) {}
18}
19class D extends C {
20    public function method($a): self {}
21    public function method2($a): D {}
22    public function method3($a): stdClass {}
23    public function method4(C $a) {}
24}
25
26// Works.
27interface I {}
28interface J extends I {}
29class E {
30    public I|J $prop;
31    public function method($a): I {}
32}
33class F extends E {
34    public J|I $prop;
35    public function method($a): J {}
36}
37
38// Requires K & L, delay to runtime.
39class G {
40    public function method($a): K {}
41}
42class H extends G {
43    public function method($a): L {}
44}
45
46// Early-binding preventer.
47class Z {
48    public function method(X $a) {}
49}
50