Bug #63911 [Opn->Csd]: Ignore conflicting trait methods originationg from identical sub traits

From: Date: Wed, 22 Nov 2017 17:11:13 +0000
Subject: Bug #63911 [Opn->Csd]: Ignore conflicting trait methods originationg from identical sub traits
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212680@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63911&edit=1 ID: 63911 Updated by: pmmaga@php.net Reported by: bitluni at bitluni dot net Summary: Ignore conflicting trait methods originationg from identical sub traits -Status: Open +Status: Closed Type: Bug Package: Class/Object related Operating System: * PHP Version: 5.6.9 -Assigned To: +Assigned To: pmmaga Block user comment: N Private report: N New Comment: The fix for this bug has been committed. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. For Windows: http://windows.php.net/snapshots/ Thank you for the report, and for helping us make PHP better. Fixed with commit: http://git.php.net/?p=php-src.git;a=commit;h=179ed6e43d9703fe6bdaa286aec79f7e131a8ab0 Previous Comments: ------------------------------------------------------------------------ [2017-09-04 11:04:20] nicolas dot giraud dot dev at gmail dot com I experiment the same issue here and it is very unpleasant. https://3v4l.org/nnvOK Plus, the error message is frustrating as it tells there are collisions while there are not! :( ------------------------------------------------------------------------ [2015-12-12 15:44:15] serovov at gmail dot com I would like to add another test case to this issue. It should handle same methods not only from sub-traits but also from current class. Thanks! <?php trait helper { public function helper() {} } trait util_useful { use helper; public function do_something_useful() {$this->helper(); return 'useful';} } trait util_useless { use helper; public function do_something_useless() {$this->helper(); return 'useless';} } class utils { use helper; use util_useful; use util_useless; public function use_helper() { $this->helper();} } $ob = new utils(); echo $ob->do_something_useful(), "\n"; echo $ob->do_something_useless(), "\n"; echo $ob->use_helper(), "\n"; ?> ------------------------------------------------------------------------ [2015-06-09 14:13:32] cmb@php.net Related To: Bug #69774 ------------------------------------------------------------------------ [2015-06-09 14:12:04] cmb@php.net I would assume that a use statement simply injects the members of the trait into the lexically current class/trait. So B and C in the test script of the OP have separate a() methods, which leads to a conflict when both traits are used in D. The section "The Flattening Property" in the respective RFC[1] supports this assumption: | Traits are only entities of the literal code written in your | source files. There is no notion about Traits at runtime. They | are used to group methods and reuse code and are totally | flattened into the classes composed from them. It is almost like | a language supported and failsafe copy'n'paste mechanism to | build classes. The section "Traits Composed from Traits"[2] furthermore states: > Since Traits are fully flattened away at compile time it is > possible to use Traits to compose Traits without any additional > impact on the semantics. According to that information I would say the behavior is to be expected, and as such is not a bug, but rather needs to be documented in the PHP manual. As gron stated otherwise, I'm assigning to him. Stefan, can you please have a look at this issue? See also <http://3v4l.org/RkYH5>. [1] <https://wiki.php.net/rfc/horizontalreuse#the_flattening_property> [2] <https://wiki.php.net/rfc/horizontalreuse#traits_composed_from_traits> ------------------------------------------------------------------------ [2015-03-17 15:02:57] paul at edunation dot co dot uk Fixing this issue could make traits a far more useful composition tool! (and avoid countless insteadof statements) If tampering with the "use" statement is problematic, could an explicit "use_once" statement not add a simple, per-class usage check for a given trait? ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=63911 -- Edit this bug report at https://bugs.php.net/bug.php?id=63911&edit=1

« previous php.bugs (#212680) next »