True or False: In PHP 5.4 Traits can have properties?
..
..
..
..
..
..
..
..
..
..
ANSWER:
True!
In PHP 5.4 Traits may contain properties as long as properties do not exist in the calling class. But beware, if the property already exists PHP will throw an error (fatal if the property isn’t identical to the trait property, and E_STRICT if it is).
12345678910 trait demo {public $demo = 'this is a demo';public $test = 'this is a test';public function cool() {/* this is the method */}/* ... */}Valid
12345678910111213 trait testTrait {public $demo = 'test';}class testClass {use testTrait;function test() {echo $this->demo;}/* ... */}E_STRICT Error
1234567891011 trait testTrait {public $demo = 'test';}class testClass {use testTrait;public $demo = 'test';/* ... */}Fatal Error:
1234567891011 trait testTrait {public $demo = 10;}class testClass {use testTrait;public $demo = 'test';/* ... */}Fatal Error:
1234567891011 trait testTrait {public $demo = 'test';}class testClass {use testTrait;protected $demo = 'test';/* ... */}.
PHP Manual:
http://php.net/manual/en/language.oop5.traits.php



