Re: [RFC] [Discussion] `#[\Override]` for class constants
| From: | Tim Düsterhus | Date: | Thu, 02 Apr 2026 09:25:31 +0000 |
| Subject: | Re: [RFC] [Discussion] `#[\Override]` for class constants | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130529@lists.php.net to get a copy of this message | ||
Hi
Am 2026-03-31 01:36, schrieb Daniel Scherzer:
I'd also like to draw specific attention to the open question, which I am
soliciting feedback on: how should #[\Override] work for enum cases? See
the RFC page for details.
We've been pretty clear so far the “enum cases are just constants”, e.g. in the RFC for #[\Deprecated] (https://wiki.php.net/rfc/deprecated_attribute):
Enum cases are internally implemented as class constants. Adding the #[\Deprecated] attribute to an enum case will behave as expected.Given that:
interface NamedX {
public const string Name = 'foo';
}
enum Foo implements NamedX {
case Name;
}
is a thing already and fails with:
Type of Foo::Name must be compatible with Named::Name of type stringas expected and
interface NamedX {
public const Name = 'foo';
}
enum Foo implements NamedX {
case Name;
}
without defining the constant's type just works by the enum case shadowing the interface’s constant it seems consequent to allow #[\Override] on enum cases, even if likely not particularly useful.
Best regards
Tim Düsterhus