New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Forbidding constant "overriding" #37
Comments
That is absolutely not an "edge case" but PHP's implementation of "one-time programmability". I think that this behavior is great because you may override it in every descendant once, then (mostly) prevent further tampering. Changing the type of it if not already alarmed upon, however, should be implemented in my opinion, (unless it is declared as NULL by default, which is what we do sometimes to mimic abstract constant behavior - we certainly do change it always to the same type though). I am unsure if the above could be done in any concise and straightforward manner. |
I would agree if constants were not implicitly inherited, but as it is now it's only confusing and error-prone. Also constants can't be |
I guess this "confusion" stuff be "Java-specific". In C#, for instance, you may declare a constant as "new" in a descendant, so that it is actually overridden (and even that is needed only due to compile-time substitution); whilst in C, you can just #undef practically anything to redefine it. What I do agree to is, however, that regardless of "declaring" strict types, no notice or anything is received when the type of a constant is changed; and also there seems no way to declare the type of a class constant. |
@ondrejmirtes WDYT about this one, is it worth pursuing? |
Const overrides violate const invariants and are not LSP-compliant (types can be changed randomly).
There may be dragons when constants are used with
static::
(sniff request to forbid that: slevomat/coding-standard#473) or$object::
.Any occurence of a constant override should be (abstract) method instead.
Edge case: constants like
NAME
on each member of a tree?The text was updated successfully, but these errors were encountered: