|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
[2017-03-18 21:00 UTC] bugsphp077 at nabialek dot org
-Operating System: Windows
+Operating System: Linux/Windows
[2017-03-18 21:00 UTC] bugsphp077 at nabialek dot org
[2017-03-18 21:09 UTC] requinix@php.net
-Summary: It's possible to override trait property with
different value
+Summary: It's possible to override trait property with
different loosely-equal value
-Status: Open
+Status: Verified
[2017-03-18 21:09 UTC] requinix@php.net
[2017-05-01 11:00 UTC] nikic@php.net
[2017-05-01 11:00 UTC] nikic@php.net
-Status: Verified
+Status: Closed
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 17:00:01 2025 UTC |
Description: ------------ According to PHP manual: "If a trait defines a property then a class can not define a property with the same name unless it is compatible (same visibility and initial value), otherwise a fatal error is issued. Before PHP 7.0.0, defining a property in the class with the same visibility and initial value as in the trait, raised an E_STRICT notice. " but it seems it's not completely true. Some casts are done, so in fact you can use different value. Test script: --------------- trait PropertiesTrait { public $same = true; public function message() { if ($this->same === true) { return "A"; } return "B"; } } class PropertiesExample { use PropertiesTrait; public $same = 2; } $example = new PropertiesExample(); echo $example->message(); Expected result: ---------------- Fatal error as described in documentation. Actual result: -------------- B (Same result is for PHP 7.1.1). No warning/notice is generated