Re: RFC: Trait expects interface

From: Date: Thu, 06 Jan 2022 23:53:05 +0000
Subject: Re: RFC: Trait expects interface
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-116842@lists.php.net to get a copy of this message
In your use cases, are these traits generally *using* the interface methods, or *implementing* them?
It is both. However "implementing" case is more problematic, since "using" can be quite reliably handled by adding `assert($this instanceof LoggerInterface)` or type hints in trait methods - SCA tools should handle this and PHP will complain if interface is not implemented. But there is no easy way to say "FooTrait::someMethod() is implementation of FooInterface::someMethod()" that PHP and SCA will understand. And I think this proposal handles this quite well, since it does not introduce implicit "implements" (IMO introducing another way of "injecting" interfaces to classes will just hurt readability) - you still needs to add interface to "implements" section in class definition, but traits have more tools to define its purpose and ensure that classes have proper definition. -- Regards, Robert Korulczyk

« previous php.internals (#116842) next »