note 126868 deleted from language.oop5.constants by cmb
| From: | cmb@php.net | Date: | Tue, 22 Feb 2022 10:48:20 +0000 |
| Subject: | note 126868 deleted from language.oop5.constants by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217642@lists.php.net to get a copy of this message | ||
Note Submitter: Patanjali
----
To the commenter who wrote:
'Also I don't understand which are the advantages of modifying the class scope of a
constant because constant couldn't be change at runtime.'
Any public member of a class invites users of that class to create dependencies on it in their code.
If a class constant -- or any member -- is only required internally to that class, then external
dependencies on it need to be prevented by using using the 'private' modifier, because a
class creator doesn't want to be constrained by the past if they don't need to, especially
if the constant value might change with class version.
This is part of the encapsulation purpose for classes.
Otherwise, a public class constant is a effectively a public constant name-spaced by the class name,
which may be useful for grouping related constants which are only available if the class file is
included.