Bug #67979 [Opn->Nab]: overridding property on an inherited trait

From: Date: Mon, 08 Sep 2014 19:30:56 +0000
Subject: Bug #67979 [Opn->Nab]: overridding property on an inherited trait
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187457@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67979&edit=1 ID: 67979 Updated by: aharvey@php.net Reported by: bradley dot lee80 at googlemai dot com Summary: overridding property on an inherited trait -Status: Open +Status: Not a bug Type: Bug Package: *General Issues Operating System: MacOSx PHP Version: 5.5.16 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Previous Comments: ------------------------------------------------------------------------ [2014-09-08 14:09:33] gron@php.net This is intended behavior, because the value for @api_version differs. Traits generally require explicit conflict resolution, but properties do not support conflict resolution because of their dynamic nature. So, at the moment, you get a very conservative fatal error for everything that smells like a problematic composition. ------------------------------------------------------------------------ [2014-09-08 13:04:07] bradley dot lee80 at googlemai dot com Description: ------------ Re-declaring properties in inherited traits throws a Fatal error For this scenario I can get around it by having a method return a hard coded value instead of the property, but it will have to be re-declared in each version of the API. --- From manual page: http://www.php.net/language.oop5.traits --- Test script: --------------- <?php trait V1Trait { protected $api_version = '1.0'; public function getApiVersion() { return $this->api_version; } } trait V2Trait { use V1Trait; protected $api_version = '2.0'; } Expected result: ---------------- <void> Actual result: -------------- Fatal error: V2Trait and V1Trait define the same property ($api_version) in the composition of V2Trait. However, the definition differs and is considered incompatible. Class was composed in Traits.php on line 15 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67979&edit=1

« previous php.bugs (#187457) next »