Edit report at https://bugs.php.net/bug.php?id=55183&edit=1

 ID:                 55183
 Updated by:         g...@php.net
 Reported by:        php at bouchery dot com
 Summary:            Aliasing traits
-Status:             Assigned
+Status:             Closed
-Type:               Bug
+Type:               Feature/Change Request
 Package:            Class/Object related
 Operating System:   Windows XP
 PHP Version:        5.4.0alpha1
 Assigned To:        gron
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Hi:

Apologies for marking it "bogus", the bug-tracker isn't really polity.
Your use case is perfectly valid, but not supported.

The current behavior was designed this way intentionally.
We had lengthy discussions about an explicit exclude operator on the mailing 
list, and the consensus was that it is not desirable to have it, 
because it would break the consistency of a trait. (I did not follow that 
argument, since traits are not strongly consistent in anyway, but that was the 
result of the discussions.)

Thus, I am sorry, but this is not possible.

Furthermore, aliasing is NOT renaming.
As you noticed, it does not change anything, but just provides an _additional_ 
alias to the same method body.

I will close this issue, but feel free to start a discussion on the mailing 
list 
if you feel this is of greater importance.

Thanks
Stefan


Previous Comments:
------------------------------------------------------------------------
[2011-07-11 16:50:52] php at bouchery dot com

Description:
------------
I have 2 traits with the same method name. I don't want to keep one and rename 
(alias) the other, but rename both.


        use X, Y {
                X::set as setX;
                Y::set as setY;
        }

Test script:
---------------
<?php
trait X {
        protected $_x = 0;
        public function set($x) {
                $this->_x = $x;
        }
}

trait Y {
        protected $_y = 0;
        public function set($y) {
                $this->_y = $y;
        }
}

class MyClass {
        use X, Y {
                X::set as setX;
                Y::set as setY;
        }
}
?>

Expected result:
----------------
MyClass with 2 method and 2 properties : 
class MyClass
{
        protected $_x = 0;
        protected $_y = 0;
        public function setX($x) {
                $this->_x = $x;
        }

        public function setY($y) {
                $this->_y = $y;
        }
}


Actual result:
--------------
PHP Fatal error:  Trait method set has not been applied, because there are 
collisions with other trait methods on MyClass


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=55183&edit=1

Reply via email to