xref: /PHP-7.2/Zend/tests/traits/property009.phpt (revision f1d7e3ca)
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 unexpeted with changing traits.
3--FILE--
4<?php
5error_reporting(E_ALL | E_STRICT);
6
7class BaseWithPropA {
8  public $hello = 0;
9}
10
11// This is how publics are handled in normal inheritance
12class SubclassClassicInheritance extends BaseWithPropA {
13  public $hello = 0;
14}
15
16// And here, we need to make sure, that the traits behave the same
17
18trait AHelloProperty {
19  public $hello = 0;
20}
21
22class BaseWithTPropB {
23    use AHelloProperty;
24}
25
26class SubclassA extends BaseWithPropA {
27    use AHelloProperty;
28}
29
30class SubclassB extends BaseWithTPropB {
31    use AHelloProperty;
32}
33
34$classic = new SubclassClassicInheritance;
35var_dump($classic);
36
37$a = new SubclassA;
38var_dump($a);
39
40$b = new SubclassB;
41var_dump($b);
42
43?>
44--EXPECTF--
45object(SubclassClassicInheritance)#1 (1) {
46  ["hello"]=>
47  int(0)
48}
49object(SubclassA)#2 (1) {
50  ["hello"]=>
51  int(0)
52}
53object(SubclassB)#3 (1) {
54  ["hello"]=>
55  int(0)
56}
57