summaryrefslogtreecommitdiff
path: root/Zend/tests/type_declarations/variance/class_order_autoload_error5.phpt
blob: a6a46f84a2329f5a3e716d3a8bd9a1d047f6595a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
--TEST--
Variance error in the presence of autoloading (5)
--FILE--
<?php

spl_autoload_register(function($class) {
    if ($class == 'A') {
        class A {
            public function method(): X {}
        }
        var_dump(new A);
    } else if ($class == 'B') {
        class B extends A {
            public function method(): Y {}
        }
        var_dump(new B);
    } else if ($class == 'X') {
        class X {
            public function method(Y $a) {}
        }
        var_dump(new X);
    } else if ($class == 'Y') {
        class Y extends X {
            public function method(Z $a) {}
        }
        var_dump(new Y);
    } else if ($class == 'Z') {
        class Z extends Y {
            public function method($a) {}
        }
        var_dump(new Z);
    }
});

var_dump(new B);

?>
--EXPECTF--
object(A)#2 (0) {
}
object(X)#2 (0) {
}

Warning: Declaration of Y::method(Z $a) should be compatible with X::method(Y $a) in %s on line %d
object(Z)#2 (0) {
}
object(Y)#2 (0) {
}
object(B)#2 (0) {
}
object(B)#2 (0) {
}