Re: Initializing constants once, with code?
| From: | Mike Schinkel | Date: | Fri, 03 Jan 2020 00:39:57 +0000 |
| Subject: | Re: Initializing constants once, with code? | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-107966@lists.php.net to get a copy of this message | ||
> On Jan 2, 2020, at 7:09 PM, tyson andre <tysonandre775@hotmail.com> wrote:
>
>> The problem with using constants is that the value is still hardcoded
>> and if we later want to change to pulling the data from a config file
>> we have to change all the code that uses those constants.
>
> It's possible to work around this by using a unique constant name
> and define('unique_name', $dynamicExpression)
> (and const MY_CLASS_CONST = \unique_name;)
I do appreciate the attempt to come up with something that is a workaround.
That said, I definitely do not want to do is start using "clever" code in my
implementations because — one day — someone else will have to maintain what I write.
Really, I was just asking for a discussion of potentially allowing for one-time initialization via
code for constants and via a straightforward, obvious syntax and standardized syntax.
Effectively I am just asking for immutable static values in a class that can be access vis the
<Class>::<ImmutableValue> syntax.
-Mike