note 126868 added to language.oop5.constants
| From: | Patanjali at main dot php dot net | Date: | Tue, 22 Feb 2022 05:06:11 +0000 |
| Subject: | note 126868 added to language.oop5.constants | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217637@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 193.119.55.47)
----
Manual Page -- https://php.net/manual/en/language.oop5.constants.php
Edit -- https://main.php.net/note/edit/126868
Del: integrated -- https://main.php.net/note/delete/126868/integrated
Del: useless -- https://main.php.net/note/delete/126868/useless
Del: bad code -- https://main.php.net/note/delete/126868/bad+code
Del: spam -- https://main.php.net/note/delete/126868/spam
Del: non-english -- https://main.php.net/note/delete/126868/non-english
Del: in docs -- https://main.php.net/note/delete/126868/in+docs
Del: other reasons-- https://main.php.net/note/delete/126868
Reject -- https://main.php.net/note/reject/126868
Search -- https://main.php.net/manage/user-notes.php