Edit report at https://bugs.php.net/bug.php?id=65303&edit=1
ID: 65303 User updated by: thomas dot ene at gmail dot com Reported by: thomas dot ene at gmail dot com Summary: Make traits more flexibile Status: Not a bug Type: Feature/Change Request Package: *General Issues Operating System: - PHP Version: 5.4.17 Block user comment: N Private report: N New Comment: Many thanks Stefan, with your last comment it makes sense. Apologies for submitting this as a bug though, I was actually looking for a "feature request" section - and the closest I could find was: "Bug"/"Feature/change request". Best Regards, Thomas Previous Comments: ------------------------------------------------------------------------ [2013-07-22 08:50:26] g...@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. Hi Thomas: If I understand you correctly, it already works what you are asking for. So, this should work: dog::breathe as dogBreathe; dog::bark as dogBark; snake::breathe as snakeBreathe; snake::hiss as snakeHiss; See the last part of Example #5: http://php.net/manual/en/language.oop5.traits.php However, since `as` introduces an alias and does not do renaming, you still need to resolve the conflicts explicitly with `insteadof`. This is on purpose. While you might argue that it is not 'DRY', it makes you formulate explicitly what you need, and therefore provides some protection from unexpected changes in the traits hierarchy. Hope this helps Stefan ------------------------------------------------------------------------ [2013-07-21 00:12:39] thomas dot ene at gmail dot com Description: ------------ I find traits very useful (i've been waiting for their availability for a long time) - however I think people could benefit from having a bit more flexibility when using them - specifically when dealing with trait method renaming - rather then being forced to choose one method over the other, I think it would be useful to have the option to rename all methods from all traits to our liking. I've posted an example in the test/script section. Test script: --------------- trait dog { public function bark() { echo("Bark, bark, bark!<br>"); $this->breathe(); } public function breathe() { echo("...dog breathing...<br>"); } } trait snake { public function hiss() { echo("ssssss!<br>"); $this->breathe(); } public function breathe() { echo("...snake breathing...<br>"); } } class pugosnake { use dog, snake { //What I think it would be useful is this dog::breathe as dogBreathe; dog::bark as dogBark; // which will call the correct breathe function (dogBreathe now); snake::breathe as snakeBreathe; snake::hiss as snakeHiss; // which will also call the correct breathe function (snakeBreathe now); } } $a = new pugosnake(); $a->dogBreathe(); // Produces "Bark, bark, bark...dog breathing..." $a->snakeBreathe(); // Produces "ssssss...snake breathing..." // Right now this doesn't work as we're forced to select one breathe method over the other ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65303&edit=1