RE: [PHP-DEV] horizontal reuse: traits vs. grafts
On Wed Mar 24 06:50 AM, Lukas Kahwe Smith wrote:
> The third sentence is not so clear to me, but if I guess it its also
> just a typo as it makes more sense to me when replacing "renaming" to
> "result in renaming". But maybe you could tweak that paragraph to be a
> bit clearer. For example its still not totally clear to me why
> aliasing doesn't imply inclusion, I guess its definitely more
> flexible.
It was really unclear to me too, this example cleared it up:
http://github.com/gron/php-src/blob/PHP_5_3-traits/Zend/tests/traits/bugs/al
ias-semantics.phpt
The current trait implementation does not 'rename' the previous method but
creates an 'alias'.
> class Talker {
> use A, B {
> B::smallTalk instead A;
> A::bigTalk instead B;
> B::smallTalk as talk;
> }
> }
I think in this case, it would output 'A'.
Personally I would prefer to see:
class Talker {
use A {
public function bigTalk();
}
use B {
public function smallTalk();
public function smallTalk() as talk(); // this 'renames' the function /
not an alias
}
}
Other example:
class Talker {
use A;
use B {
public function smallTalk() as talk();
}
}
Thread (21 messages)