Re: Re: New Feature: Fully qualified class name resolution as scalar with class keyword
| From: | Nikita Popov | Date: | Wed, 18 Apr 2012 13:01:41 +0000 |
| Subject: | Re: Re: New Feature: Fully qualified class name resolution as scalar with class keyword | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-60188@lists.php.net to get a copy of this message | ||
On Wed, Apr 18, 2012 at 1:21 AM, Stas Malyshev <smalyshev@sugarcrm.com> wrote:
> Hi!
>
>> Well, not that you mention it, I don't see a reason why we shouldn't
>> add run-time resolution where necessary. For once this would allow
>
> Runtime resolution of what? We already have get_class(),
> get_called_class() and __NAMESPACE__. Now, having constant expression
> for full class name might be useful since some contexts allow only
> constant expressions. But for runtime contexts we already have it. And
> there's no such thing as run-time resolution of namespaced class names.
Yes, you are right. static::class would be equivalent to
get_called_class() and $foo::class would be equivalent to
get_class($foo).
>> static::class, but also would allow $obj::class. Not sure this is
>> really necessary, but it would be more consistent :)
>
> $obj::class means "class" constant of the class whose name is given by
> string variable $obj. Probably not what you intended. And you have
> get_class() already.
As already mentioned, There can't be a class constant called "class",
because it is a keyword. (const class = 'Foo' is a syntax error).
But yes, I agree that runtime resolution only duplicates existing
behavior, so it isn't really necessary (you could argue thought that
self::class similarly also only replicates the existing __CLASS__). It
would be nice for consistency in my eyes, but I'm good without it too
:)
Nikita