Re: RFC: Traits for PHP

From: Date: Fri, 22 Feb 2008 14:45:21 +0000
Subject: Re: RFC: Traits for PHP
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.internals 
Request: Send a blank email to internals+get-35727@lists.php.net to get a copy of this message
Marcus Boerger wrote: > Hello Lukas, > > alright, > > 'foo as bar' is ok to me and does not even add a new keyword. > Ignore or any more keywords are bad and I also think that the correct > would be hide(ing). But as I further more explained it should really be > something that only marks a method as private if at all. That can be > done as: > 'foo as private' since private is a keyword it cannot conflice anyway. I like this solution. I have been uncomfortable with the current trait suggestions because they occur in the body of the class, whereas extends/implements is outside. I think there is a way to handle this, however. class Blah extends ... implements ... traits trait1, trait2, trait3 { } The above presents a problem if trait2 contains conflicting method names, but a simple way to solve it would be to automatically alias methods by prepending traitname:: <?php trait trait1 { function a(){}} trait trait2 { function a(){}} class Blah extends ... implements ... traits trait1, trait2, trait3 { } ?> would create method "trait2::a" and we can alias it in the class body. Also, $a->{'trait2::a'}(); is legal syntax, so no problems there. Example: <?php trait trait1 { function a(){}} trait trait2 { function a(){}} class Blah extends ... implements ... traits trait1, trait2, trait3 { function trait2::a as b; } ?> This would be 100% obvious to me, and far clearer for reading since we would be explicitly saying we're aliasing a function. So, I rescind my previous syntax suggestion in favor of the above. Greg

« previous php.internals (#35727) next »