RFC: Trait expects interface

From: Date: Tue, 04 Jan 2022 22:35:38 +0000
Subject: RFC: Trait expects interface
Groups: php.internals 
Request: Send a blank email to internals+get-116802@lists.php.net to get a copy of this message
Hello internals! Since «traits» are often an indicator of not very good code and many may not use them quite correctly, for example, as helpers, I suggest adding support for the expects keyword to indicate that the trait is part of the code decomposition taking into account ISP. For example: ``` // Definition trait LoggerTrait expects LoggerInterface {     // ... } // Usage class MyService {     use LoggerTrait; // Fatal Error: Class MyService expects LoggerInterface to be implemented } class MyService2 implements LoggerInterface {     use LoggerTrait; // OK } ``` How relevant do you think this idea/proposal is? And what possible problems or solutions will this entail in the future?   -- Kirill Nesmeyanov

« previous php.internals (#116802) next »