Re: Add support for ::class to constant()

From: Date: Mon, 15 Mar 2021 14:58:23 +0000
Subject: Re: Add support for ::class to constant()
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-113540@lists.php.net to get a copy of this message
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)

« previous php.internals (#113540) next »