|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-07-22 08:50 UTC] gron@php.net
-Status: Open
+Status: Not a bug
[2013-07-22 08:50 UTC] gron@php.net
[2013-07-23 10:16 UTC] thomas dot ene at gmail dot com
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 27 07:00:01 2025 UTC |
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