File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Zend/tests/type_declarations/variance Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Use of parent inside a class that has / has no parent
3
+ --FILE--
4
+ <?php
5
+
6
+ // Illegal: A::parent is ill-defined
7
+ class A {
8
+ public function method (parent $ x ) {}
9
+ }
10
+ class B extends A {
11
+ public function method (parent $ x ) {}
12
+ }
13
+
14
+ // Legal: A2::parent == P2
15
+ class P2 {}
16
+ class A2 extends P2 {
17
+ public function method (parent $ x ) {}
18
+ }
19
+ class B2 extends A2 {
20
+ public function method (P2 $ x ) {}
21
+ }
22
+
23
+ // Legal: B3::parent == A3 is subclass of A3::parent == P3 in covariant position
24
+ class P3 {}
25
+ class A3 extends P3 {
26
+ public function method ($ x ): parent {}
27
+ }
28
+ class B3 extends A3 {
29
+ public function method ($ x ): parent {}
30
+ }
31
+
32
+ // Illegal: B4::parent == A4 is subclass of A4::parent == P4 in contravariant position
33
+ class P4 {}
34
+ class A4 extends P4 {
35
+ public function method (parent $ x ) {}
36
+ }
37
+ class B4 extends A4 {
38
+ public function method (parent $ x ) {}
39
+ }
40
+
41
+ ?>
42
+ --EXPECTF--
43
+ Warning: Declaration of B4::method(A4 $x) should be compatible with A4::method(P4 $x) in %s on line 36
44
+
45
+ Warning: Declaration of B::method(A $x) should be compatible with A::method(parent $x) in %s on line 36
You can’t perform that action at this time.
0 commit comments