On 21.04.21 15:14, Christian Schneider wrote:
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.

Such restrictions also convey information and intent. One could argue
defining a specific return type to a method is restricting its use, but
it also clarifies how something should work and avoids unintended
changes. final constants might be more niche, but it gives you a choice
on how you want a class constant to behave if child classes are
necessary and possibly done by someone else.

Having "final" for constants seems a good addition to me, especially if
the inconsistent behavior with interface constants can be solved at the
same time.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to