Hey Marco,
thanks for giving your reasons!
> traits are pretty much unnecessary in the language.
Perhaps for this RFC it is necessary to first provide use cases for traits and
defend themselves before trait constants.
It's understandable that this is a premise that needs to be shared first,
since trait was originally a mechanism designed to replace certain uses of
inheritance, and inheritance itself is an enough controversial feature in
today's PHP world.
This discussion on "how traits should be treated today" is probably an
important point for the community, but I will reply to this in a separate email,
so I will first consider the other points in this email.
> invariants shared by trait (example in the RFC) are generally to be
> separated to clear invariant objects/functions/static methods, instead of
> being put in a trait
I did not understand the intent here. I think both traits and classes are
examples of mechanisms to package behavior and data. Why is it
allowed for classes to represent invariants by const, but not for traits?
> a trait does not know the public API of its implementor either, so
> self::SOME_CONSTANT inside a trait points nowhere sensible, since
> there is no clear contract on the possible implementations.
Since the proposed trait constants cannot be overridden in the
composing class, their definition serves as a sort of contract for the
internal implementation of the trait.
> Referencing symbols of the implementing class in a trait is a clear
> mistake (again, an example from the RFC)
I agree with this point.
And avoiding this is one of the main goals of this RFC.
> this expands trait compatibility checks, introducing a number of
> potential error scenarios
I am skeptical of the claim that this is a problem that the introduction of
trait constants itself has.
If there is a situation where this is really a problem, it would be another
problem where members of traits have no choice but to share namespaces within
the composing class, so I think it would be better to solve this with another
proposal.
Whether we should solve the name conflict problem with another proposal will
ultimately come down to the question of how we should deal with traits in the
future, though.
Thanks!
--
Shinji Igarashi
2022年7月6日(水) 18:46 Marco Pivetta <ocramius@gmail.com>: