On Thu, Feb 18, 2016 at 5:35 AM Larry Garfield <la...@garfieldtech.com> wrote:
> On Wed, Feb 17, 2016, at 01:05 PM, Kevin Gessner wrote: > > On Wed, Feb 17, 2016 at 9:25 AM, Kevin Gessner <kgess...@etsy.com> > wrote: > > > > > Hello internals team! I'd like to propose an RFC to allow traits to > > > implement interfaces. > > > > > > > I've created a proper RFC wiki page here with the draft: > > https://wiki.php.net/rfc/traits-with-interfaces > > > > It includes more detail and several example code snippets. Thanks all > > for > > your feedback so far. > > Thanks, Kevin. > > At the risk of a "me too" post, I would also be in favor of allowing > traits to declare an interface but NOT in favor of a use-ing class > implicitly implementing the interface as a result. I'd rather the class > still need to self-declare the interface; that it uses a trait to > fulfill that contract is irrelevant to the outside world. > I agree, in theory, but I also think we introduce confusion. Every other OO rule says you get "everything*" from what you are using (extending a subclass gets you all the parent classes, implementing an interface that extends an interface gets you the parent interface, using a trait that uses a trait gets you both traits, etc). Perhaps we need a different keyword? trait foo providesfor myInterface { } I'm not sold on that keyword, it's just the first thing that came to mind. *I know you don't get private methods and properties in subclasses, but that's something dictated by the class itself. The class says "you can't have these if you extend me" instead of the engine saying "you aren't implementing that when you use the trait because it's a trait" At that point, the benefit becomes two-fold: > > 1) Communicate to users of the trait what the intent of the trait is: To > provide the boilerplate for some interface, or portion thereof. This > could be covered by PHPDoc, potentially, and I've suggested the same for > PSR-5 before. > > Agreed > 2) Ask the engine to do a syntax check on the class to make sure I did > not forget something or screwed up in some way. That is, not fulfilling > the interface on the trait would cause a parse error (or an error in my > IDE), forcing me to fix my bug before I even try running it. PHPDoc > would NOT have this benefit. > > Thus I feel this addition does have value that a PHPDoc alternative > would not. > > Good point. I was of the opinion "we can just use comments to declare intent," but hadn't really thought of using the engine in this way. It makes sense. > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- -- Chase chasepee...@gmail.com