PHP wishlist/combine traits and interfaces
|adapted from a 2021-08-19 post on TootCat|
interfaces and traits even different things?
Here's everything you can do with an
interface (that I care about, anyway):
- extend another
- "implement" it in a class ("
- use it as a parameter type
Item 1 (functions)
This is functionally the same as defining an
abstract public function in a trait.
Item 2 (extend)
This is functionally the same as a
trait use-ing another
Item 3 (implementation)
This is functionally the same as
trait that consists entirely of
abstract public functions.
Item 4 (parameter type)
This is the one thing a
trait cannot do -- but I don't understand why it was done that way.
Combining these two ideas into a single keyword would both simplify the language and make it more powerful, I'd think.
This seems related to my trait implements wishlist item from earlier. At first I thought that they might be in conflict, but on looking at the syntax in more depth, I don't see how. A
trait that uses/extends another
trait is also declaring
abstract functions in that
trait as an implementation requirement.