Traits with interfaces

From: Date: Wed, 28 Feb 2018 20:57:30 +0000
Subject: Traits with interfaces
Groups: php.internals 
Request: Send a blank email to internals+get-101941@lists.php.net to get a copy of this message
Why traits doesn't supports interfaces (via implements) like classes does? It could be useful when trait implements part of abstract functions from interface, then the class that uses this traits should implements the another part. It could turn it possible (pseudo-code): interface VisibilityControlContract - public function isVisible(): bool; trait VisibilityControlTrait implements VisibilityControlContract - public function isVisible(): bool { ... } class UserModel (not need implements VisibilityControlContract directly) - uses VisibilityControlTrait; var_dump(new UserModel instanceof VisibilityControlContract); // true The disvantages that I can see with that is that without an IDE I could not identify easily if interface was implemented by some trait. But it too happen when I do implements an abstract class that implements some interface. -- David Rodrigues

« previous php.internals (#101941) next »