From: thomas dot ene at gmail dot com Operating system: - PHP version: 5.4.17 Package: *General Issues Bug Type: Feature/Change Request Bug description:Make traits more flexibile
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 bug report at https://bugs.php.net/bug.php?id=65303&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65303&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65303&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65303&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=65303&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=65303&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=65303&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=65303&r=needscript Try newer version: https://bugs.php.net/fix.php?id=65303&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=65303&r=support Expected behavior: https://bugs.php.net/fix.php?id=65303&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=65303&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=65303&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=65303&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65303&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=65303&r=dst IIS Stability: https://bugs.php.net/fix.php?id=65303&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=65303&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=65303&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=65303&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=65303&r=mysqlcfg