Re: Access property of object stored in a constant
| From: | Claude Pache | Date: | Sat, 19 Aug 2023 09:21:50 +0000 |
| Subject: | Re: Access property of object stored in a constant | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-120920@lists.php.net to get a copy of this message | ||
> Le 19 août 2023 à 02:18, Juliette Reinders Folmer <php-internals_nospam@adviesenzo.nl>
> a écrit :
>
>
> I totally understand that people are trying to do this, but this still very much feels like
> scope creep.
>
> IIRC the new in initializers feature was _intended_ only for enums (which can't take
> properties). Now suddenly a "constant" would no longer be constant... In which case,
> what's the point of declaring it as a constant ?
>
> Smile,
> Juliette
Hi,
It might not be the original intended use. But people are entitled to use features if they find them
handy for their purpose. (It was the reason I end up using PHP rather than Java: because it solved
problems <https://www.npopov.com/2012/06/29/PHP-solves-problems-Oh-and-you-can-program-with-it-too.html>.)
At the time I filed https://github.com/php/php-src/issues/10497,
I was merely exploring the potential of the new ability to have an object in a constant. The
potential use I had back in my head was the following. Currently, I store some settings in global
constants. I was contemplating replacing those by properties of a readonly object stored in a global
constant. (A fatal issue I discovered later in my journey is that readonly properties can only be
initialised by code inside the class itself.)
But in any case, it is good to have regularity in the language. The fact that an object is stored in
a constant is completely orthogonal with the fact that the object is mutable, and the proposed patch
does not add new capability. (Conversely, the current limitation does not remove any capability.)
—Claude