Re: RFC: Traits for PHP
| From: | Todd Ruth | Date: | Tue, 19 Feb 2008 21:08:11 +0000 |
| Subject: | Re: RFC: Traits for PHP | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-35614@lists.php.net to get a copy of this message | ||
In case anyone is really excited about traits and traits
don't make it in soon, I'll point out that something similar
has been available in php for years. We've been implementing
traits based on the fact that "$this" has a different meaning
in php than in other languages. In php, "$this" is the most
recent object context. So... it's easy to create a trait
class and make calls to it from your non-trait class using
"::" syntax. "->" calls within the trait class automatically
go back to the non-trait class.
This makes the purists shudder and they added a STRICT
message for it. (If you're a purist please don't bother
replying with how evil I am. I already know this makes
your stomach turn.) It obviously isn't as clean
as a well defined trait feature (or doing a re-architecture
of your app to elimate the need), but if you need traits
today, this may work for you.
- Todd