just return $string, to be consistent with usual behavior of "::CONST_NAME", which allows objects and class names on the left hand side.

Having given it more thought, it seems like like $string::class should be more aligned with get_class($string), which at current throws a PHP Warning with the message:

"PHP Warning: get_class() expects parameter 1 to be object, string given in ..."


From the RFC:

I'm not sure whether we should do that, as I can't imagine a context
in which this would be useful, and the fact that the class name is
not validated or loaded might be more unexpected here than usual.

Yes, this would be odd and not useful:

    $hi = 'hello world';
    echo $hi::class // output: hello world

Besides that though, not sure what you mean by:

Open Question: Additionally, it would be possible to also allow $object
to be string, in which case the string would be returned verbatim. This
would be consistent with the $className::CONST_NAME syntax.

As undefined class constants are fatal errors...?

https://3v4l.org/hGW82


Cheers,
-ralph

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to