xref: /PHP-8.1/Zend/tests/traits/property009.phpt (revision 0b4778c3)
1--TEST--
2Handling of public fields with traits needs to have same semantics as with normal inheritance, however, we do add strict warnings since it is easier to run into something unexpected with changing traits.
3--FILE--
4<?php
5
6class BaseWithPropA {
7  public $hello = 0;
8}
9
10// This is how publics are handled in normal inheritance
11class SubclassClassicInheritance extends BaseWithPropA {
12  public $hello = 0;
13}
14
15// And here, we need to make sure, that the traits behave the same
16
17trait AHelloProperty {
18  public $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 (1) {
45  ["hello"]=>
46  int(0)
47}
48object(SubclassA)#2 (1) {
49  ["hello"]=>
50  int(0)
51}
52object(SubclassB)#3 (1) {
53  ["hello"]=>
54  int(0)
55}
56