Re: [RFC][Dynamic class constant fetch]
| From: | Larry Garfield | Date: | Fri, 04 Nov 2022 14:58:56 +0000 |
| Subject: | Re: [RFC][Dynamic class constant fetch] | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118966@lists.php.net to get a copy of this message | ||
On Fri, Nov 4, 2022, at 9:45 AM, Ralf Lang wrote:
> Hi Ilija,
>
> Am 04.11.2022 um 15:25 schrieb Ilija Tovilo:
>> Please let me know if you have any thoughts.
>>
>> Ilija
>
> That new way of accessing class constants dynamically does not really
> make things more readable for me. Maybe I just need to get used to it,
> but especially that last example would make my head spin without
> additional comments:
>
> Foo::{test('foo')}::{test('bar')}; Maybe I miss the use case. What kind
> of code would benefit
> from this? Wouldn't just using constant() for dynamically built
> constant
> strings be more legible? Maybe in a separate line? In the past I used a
> lot of flag constants backed by integers. A lot of these use cases have
> become classes/types in their own right since. When do you use these
> constants? Just my thoughts.
Dynamically building strings for syntax is almost never more legible. :-) I doubt you'd ever
double them up the way some of the examples show.
In practice, the single Class::{$const} or Enum::{$name} would be the most common uses, I predict,
and those are way nicer to read than the 3x longer constant() with string concat.
--Larry Garfield