Bug #69911 [Opn->Nab]: Interface apply to trait

From: Date: Fri, 06 Mar 2020 10:25:05 +0000
Subject: Bug #69911 [Opn->Nab]: Interface apply to trait
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225922@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69911&edit=1 ID: 69911 Updated by: nikic@php.net Reported by: igor at glagola dot ru Summary: Interface apply to trait -Status: Open +Status: Not a bug Type: Bug Package: Compile Failure Operating System: Linux PHP Version: 5.6.10 Block user comment: N Private report: N New Comment: The "T::m as m2" syntax does not rename the method, it adds an alias. As such, the trait method with the original name is still imported and does indeed inflict with the interface. I don't think there is any way to prevent the trait method from being added (all conflict resolution is about conflicts between traits, while here you want to say that the parent method should be used). I think the way around it is to write this: class BB extends CC implements SomeInterface { use TheTrait { TheTrait::theAction as otherAction; } public function theAction() { return parent::theAction(); } } Previous Comments: ------------------------------------------------------------------------ [2015-06-23 11:14:48] igor at glagola dot ru Description: ------------ Hi, I've got strange name collision, interface applies to trait's method before trait's method rename statement. Test script: --------------- <?php interface SomeInterface { public function theAction(); } trait TheTrait { public function theAction($param) { } } class CC { public function theAction() { } } class BB extends CC implements SomeInterface { use TheTrait { TheTrait::theAction as otherAction; } } Expected result: ---------------- I expect no errors Actual result: -------------- PHP Fatal error: Declaration of TheTrait::theAction() must be compatible with SomeInterface::theAction() in /tmp/a.php on line 22 PHP Stack trace: PHP 1. {main}() /tmp/a.php:0 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69911&edit=1

« previous php.bugs (#225922) next »