Am 21.04.2021 um 14:25 schrieb Máté Kocsis <kocsismat...@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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php