[php-src] Issue #11435: Promoted trait interface

From: Date: Mon, 12 Jun 2023 10:07:32 +0000
Subject: [php-src] Issue #11435: Promoted trait interface
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-244668@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11435 Author: mvorisek ### Description There are valid usecases where traits, multi-inheritance, define public interface. Currently checking if a class implements a trait is complex as it must traverse all uses in all parent classes using a custom code. The best solution to check for some method is simply an explicitly defined interface, but currently it requires an interface to be manually added to the class where trait is added. This requires more code and the explicit interface can be even omitted by a mistake This is a feature request to allow to specify an interface in trait directly. When such trait is used, it will promote the interface to the class where used. And same as with abstract classes, it will be required to be implemented no later than in the 1st non-abstract class. ``` <?php interface I { public function f(): void; } // (already supported) abstract class does not have to implement interface abstract class X implements I {} // trait should be able to define interface, but it doesn't need to implemented // until used in non-abstract class trait T implements I {} abstract class X2 { use T; } class X3 extends X2 { public function f(): void { } } var_dump((new X3()) instanceof T); // must print true ```

« previous php.bugs (#244668) next »