Re: [RFC] [Draft] Final constants
| From: | Christian Schneider | Date: | Wed, 21 Apr 2021 13:14:05 +0000 |
| Subject: | Re: [RFC] [Draft] Final constants | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-114087@lists.php.net to get a copy of this message | ||
Am 21.04.2021 um 14:25 schrieb Máté Kocsis <kocsismate90@gmail.com>:
>> My point is actually what’s your scenario for a final constant? If you
>> want to make sure the value you access are not changed by child class,
>>
self:: can serve the purpose already. If you want to make
>> sure
>
>
> Yes, my intention is to actually make class constant overriding impossible
> when it is desired. You can't really achieve this with only using self::,
> since you can only control your own code. Yes, I know that child classes
> could still declare a new class constant to overcome this limitation, but
> at least there will be no doubt what they should expect if they try to
> override the constant value. Otherwise, they have to check whether the
> parent class uses self:: or static:: calls.
I never really understood the desire to restrict how people can use your code.
If there is no good reason to override the value of a class constant people won't do it.
If there might be a good reason (even one you as the original designer didn't predict) then why
not leave that door open.
While I understand the theoretical benefit of being able to specify this behavior I do think it is
almost always counter productive and not a pattern I would encourage. Especially not in a dynamic
language like PHP.
- Chris