Re: Add support for ::class to constant()
On Tue, Mar 9, 2021 at 11:16 PM Kévin Dunglas <kevin@dunglas.fr> wrote:
> Hi folks,
>
> Currently, it's not possible to use the ::class special constant with the
> constant() function. This doesn't work:
>
> var_dump(
> constant('\DateTime::class')
> );
>
> For instance, Twig's constant() helper internally uses this PHP function,
> consequently the following Twig template doesn't work:
>
> myObject contains a random object, retrieve its class:
> {{ constant('class', myObject) }}
>
> I wrote a patch adding support for ::class:
> https://github.com/php/php-src/pull/6763
> As this probably qualifies as a new feature, should I write an RFC too?
>
I'm not a fan of this change. X::class is not a constant, it just happens
to share the same syntax. I think that
https://github.com/php/php-src/pull/6763#issuecomment-795046502
makes the
key point that if this is treated as a proper class constant in constant(),
then it should also be treated as such everywhere else, including
reflection. And I really don't think we want to do that.
Regards,
Nikita
Thread (4 messages)