xref: /PHP-5.5/Zend/tests/traits/property009.phpt (revision 525dd55e)
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--
45Strict Standards: BaseWithPropA and AHelloProperty define the same property ($hello) in the composition of SubclassA. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %s on line %d
46
47Strict Standards: BaseWithTPropB and AHelloProperty define the same property ($hello) in the composition of SubclassB. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %s on line %d
48object(SubclassClassicInheritance)#1 (1) {
49  ["hello"]=>
50  int(0)
51}
52object(SubclassA)#2 (1) {
53  ["hello"]=>
54  int(0)
55}
56object(SubclassB)#3 (1) {
57  ["hello"]=>
58  int(0)
59}