Re: Add support $object::class
| From: | Anthony Ferrara | Date: | Mon, 27 Apr 2015 15:35:54 +0000 |
| Subject: | Re: Add support $object::class | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-85968@lists.php.net to get a copy of this message | ||
On Mon, Apr 27, 2015 at 7:18 AM, S.A.N <ua.san.alex@gmail.com> wrote:
> Now this code causes an error PHP 5-7.
>
> PHP Parse:
> Syntax error, unexpected 'class' (T_CLASS), expecting identifier
> (T_STRING) or variable (T_VARIABLE) or '{' or '$'
>
> Do not want to use get_class($object)
Why not?
Seriously, why not? ::class was added because there was no easy way to
get from the symbol class name to the string representation of it (you
couldn't pass it to a function, etc since it would look like a
constant). So ::class is a purely compile time construct to turn a
literal classname into a string representation.
However, if you have a variable, there already is a way to do that at
runtime: get_class. What's the problem with that where we need to
further support arbitrary syntax?
Note: I'm not saying we shouldn't add support. I'm just saying that
it's not the same situation as with Bar::class...
Anthony