Stefan Marr wrote:

<snip>

> To get rid of exclude and rename I would like to propose the following:
> 
> //Example from the RFC with the cross-over conflict to be solved
> trait A {
>   public function smallTalk() {
>     echo 'a';
>   }
>   public function bigTalk() {
>     echo 'A';
>   }
> }
> 
> trait B {
>   public function smallTalk() {
>     echo 'b';
>   }
>   public function bigTalk() {
>     echo 'B';
>   }
> }
> 
> //here the new notion of combing traits and resolving conflicts upfront
> class Talker {
>   use A, B {
>      B::smallTalk instead A::smallTalk;
>      A::bigTalk instead B::bigTalk;
>      A::bigTalk as talk;
>    }
>  }

This is far better than the original proposal.

My only objection is that this introduces two new keywords, trait and
instead.  In addition, this can get very awkward if multiple traits
(more than 2) implement the same method name.  I would prefer a simple
recycling of the "=" sign for both use cases (I'd also accept = for
override, "as" for alias).

class Talker {
  use A, B, C, D {
    smallTalk = A::smallTalk; // this says that if B, C or D implement
smallTalk, it is ignored
    talk = A::bigTalk;
  }
}

To everyone - this is an aliasing procedure, not a renaming one, and
won't affect internal methods of a trait (such as if B::whatever used
B::smallTalk), as Richard Quadling incorrectly suggested.

Greg

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to