xref: /PHP-8.3/Zend/tests/traits/property008.phpt (revision 72c3eded)
1--TEST--
2Handling of private fields with traits needs to have same semantics as with normal inheritance.
3--FILE--
4<?php
5
6class BaseWithPropA {
7  private $hello = 0;
8}
9
10// This is how privates are handled in normal inheritance
11class SubclassClassicInheritance extends BaseWithPropA {
12  private $hello = 0;
13}
14
15// And here, we need to make sure, that the traits behave the same
16
17trait AHelloProperty {
18  private $hello = 0;
19}
20
21class BaseWithTPropB {
22    use AHelloProperty;
23}
24
25class SubclassA extends BaseWithPropA {
26    use AHelloProperty;
27}
28
29class SubclassB extends BaseWithTPropB {
30    use AHelloProperty;
31}
32
33$classic = new SubclassClassicInheritance;
34var_dump($classic);
35
36$a = new SubclassA;
37var_dump($a);
38
39$b = new SubclassB;
40var_dump($b);
41
42?>
43--EXPECT--
44object(SubclassClassicInheritance)#1 (2) {
45  ["hello":"BaseWithPropA":private]=>
46  int(0)
47  ["hello":"SubclassClassicInheritance":private]=>
48  int(0)
49}
50object(SubclassA)#2 (2) {
51  ["hello":"BaseWithPropA":private]=>
52  int(0)
53  ["hello":"SubclassA":private]=>
54  int(0)
55}
56object(SubclassB)#3 (2) {
57  ["hello":"BaseWithTPropB":private]=>
58  int(0)
59  ["hello":"SubclassB":private]=>
60  int(0)
61}
62