xref: /PHP-5.5/Zend/tests/traits/property001.phpt (revision 85816462)
1--TEST--
2Potentially conflicting properties should result in a strict notice. Property use is discorage for traits that are supposed to enable maintainable code reuse. Accessor methods are the language supported idiom for this.
3--FILE--
4<?php
5error_reporting(E_ALL);
6
7trait THello1 {
8  private $foo;
9}
10
11trait THello2 {
12  private $foo;
13}
14
15echo "PRE-CLASS-GUARD-TraitsTest\n";
16error_reporting(E_ALL & ~E_STRICT); // ensuring that it is only for E_STRICT
17
18class TraitsTest {
19	use THello1;
20	use THello2;
21}
22
23error_reporting(E_ALL | E_STRICT);
24
25echo "PRE-CLASS-GUARD-TraitsTest2\n";
26
27class TraitsTest2 {
28	use THello1;
29	use THello2;
30}
31
32var_dump(property_exists('TraitsTest', 'foo'));
33var_dump(property_exists('TraitsTest2', 'foo'));
34?>
35--EXPECTF--
36PRE-CLASS-GUARD-TraitsTest
37PRE-CLASS-GUARD-TraitsTest2
38
39Strict Standards: THello1 and THello2 define the same property ($foo) in the composition of TraitsTest2. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %s on line %d
40bool(true)
41bool(true)