Hi Ayesh,
On 24/06/2024 08:53, Ayesh Karunaratne wrote:
- Why is it a class-level flag and not an attribute (similar to the
`#[Override]` attribute in PHP 8.3) ?
I believe Tim already answered this, and I understood his reasoning to
be that keywords are used when they modify behaviour in a way that is
meaningful for the consumer of that class. Or to put it another way,
attributes are purely informational. For me personally, introducing an
attribute never crossed my mind, and since we already have the keyword
in the language performing a similar function in PHP, and other
languages already, it seems nonsense to contemplate anything else.
- Can a subclass extend a static parent class without using the
`static` keyword in the subclass? This will avoid a lot of BC issues
if a library decides to declare classes as static.
No, a static parent implies a static child, but implied or not, it must
still be specified explicitly. I may need to clarify that in the RFC, so
thanks for the question.
- Are there any opt-out mechanisms for subclasses?
Not sure what you mean exactly, but if you mean, can a static subclass
suddenly become non-static, the answer is no.Again thanks for the
question, as this is also something I had no previously considered.
- Can you mark interfaces, abstract classes, and Enums as static?
It seems others avoided addressing this question, and honestly I was not
really sure where to go with this one. What would it mean for an enum to
be static? I thought the whole point was we can type a group of values,
but static classes have no meaning within the type system, so I cannot
see the application.
As for abstract classes, the current version of the RFC (1.2) now
declares static mutually exclusive with abstract, so the answer there is
also no.
For interfaces, I haven't given this a great deal of thought. In
principle I don't think a static interface is especially useful, but I
could be wrong about this. Nevertheless, it is not something I intend
for this RFC, since even just static classes already have their
detractors, and expanding its scope any further is probably placing it
further in danger of rejection. So for now, the answer is also no, but
static interfaces seem like a reasonable extension to this work if there
is interest in future.
Cheers,
Bilge