Bug #74269 [Ver->Csd]: It's possible to override trait property with different loosely-equal value

From: Date: Mon, 01 May 2017 11:00:16 +0000
Subject: Bug #74269 [Ver->Csd]: It's possible to override trait property with different loosely-equal value
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-208883@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74269&edit=1 ID: 74269 Updated by: nikic@php.net Reported by: bugsphp077 at nabialek dot org Summary: It's possible to override trait property with different loosely-equal value -Status: Verified +Status: Closed Type: Bug Package: Class/Object related Operating System: Linux/Windows PHP Version: 7.0.17 Block user comment: N Private report: N New Comment: Automatic comment on behalf of mail@pmmaga.net Revision: http://git.php.net/?p=php-src.git;a=commit;h=92124f9cdc20c6a9c22f9b54092ef945c41f2bb5 Log: Fixed bug #74269: Strict comparison of initial trait property values Previous Comments: ------------------------------------------------------------------------ [2017-03-18 21:09:48] requinix@php.net The conflict detection logic uses zend_operator's compare_function, which does loose comparisons. The original RFC doesn't say whether to be strict or loose but I think the intention is that it would be strict. ------------------------------------------------------------------------ [2017-03-18 21:00:40] bugsphp077 at nabialek dot org In fact it's for both Linux and Windows ------------------------------------------------------------------------ [2017-03-18 20:58:24] bugsphp077 at nabialek dot org 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74269&edit=1

« previous php.bugs (#208883) next »