xref: /PHP-8.1/Zend/tests/bug69676_3.phpt (revision 2bba4a0d)
1--TEST--
2Bug #69676: Resolution of self::FOO in class constants not correct (variation)
3--FILE--
4<?php
5
6class P {
7    const N = 'P';
8}
9class A extends P {
10    const selfN = self::N;
11    const parentN = parent::N;
12    const N = 'A';
13}
14class B extends A {
15    const N = 'B';
16}
17
18var_dump(B::selfN); // A
19var_dump(B::parentN); // P
20
21class A2 {
22    const selfN = self::N;
23    const N = 'A2';
24}
25class B2 extends A2 {
26    const indSelfN = self::selfN;
27    const N = 'B2';
28}
29class C2 extends B2 {
30    const N = 'C2';
31}
32
33var_dump(C2::indSelfN); // A2
34
35class A3 {
36    const selfN = self::N;
37    const N = 'A3';
38}
39class B3 extends A3 {
40    const exprSelfN = "expr" . self::selfN;
41    const N = 'B3';
42}
43class C3 extends B3 {
44    const N = 'C3';
45}
46
47var_dump(C3::exprSelfN); // exprA3
48
49class A4 {
50    const selfN = self::N;
51    const N = 'A4';
52}
53class B4 extends A4 {
54    const N = 'B4';
55    public $prop = self::selfN;
56}
57class C4 extends B4 {
58    const N = 'C4';
59}
60
61var_dump((new C4)->prop); // A4
62
63?>
64--EXPECT--
65string(1) "A"
66string(1) "P"
67string(2) "A2"
68string(6) "exprA3"
69string(2) "A4"
70