Re: [IDEA for RFC] class_uses and optionally returning traits for parent classes
| From: | Claude Pache | Date: | Mon, 20 Apr 2026 09:32:03 +0000 |
| Subject: | Re: [IDEA for RFC] class_uses and optionally returning traits for parent classes | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130671@lists.php.net to get a copy of this message | ||
> Le 19 avr. 2026 à 21:01, Robert Humphries <contact@developer-rob.co.uk> a écrit :
>
> I think this is
> the strongest argument for making such a change to
class_uses -
> currently it is inconsistent with the other SPL functions (and I
> wouldn't say that modifying the function is going to cause millions of
> developers to start using the function, it is more about making the
> behaviour a little more consistent).
I think that class_uses() should never have been implemented, because it gives a false
sense of symmetry with class_implements() and class_parents(). Implemented
interfaces and parent classes can be used as types on the corresponding object (and types are
inherited), while used traits cannot. Those are fundamentally different concepts.
If, for some reason, you want to “cheat” and use traits as if they were inherited types, you are
free to do that, but I don’t think that PHP should provide a built-in function that goes beyond
what traits are intended for.
>
> (As a quick side note, what I am really looking for proposal 2 from
> https://wiki.php.net/rfc/traits-with-interfaces (or a form of
> trait
> that does this) and then using traits with interfaces for composition,
> however from what I can see on activity such as GH-11435 technical
> reasons mean this isn't likely to proceed).
See also https://wiki.php.net/rfc/interface-default-methods,
which is, I think, what is really needed.
—Claude