On Tue, May 26, 2015 at 9:52 AM, Ralph Schindler
<ra...@ralphschindler.com> wrote:
>
>
>> <?php
>>
>> namespace foo;
>>
>> function bar(){}
>>
>> var_dump(bar::class); // string(7) "foo\bar"
>>
>> ?>
>>
>> This was not explained in the RFC at all, and had I known this I would
>> have voted against it personally.
>
>
> How would you suggest it be different, if not a "compile-time name expansion
> for classes"?

Emit an opcode for it. This would also allow for dynamic lookups
($foo::class), trigger autoloading, and restrict it to classes and
interfaces (and traits?). All of these things are beneficial in my
opinion, at least.

> On a personal note, I've gotten plenty of benefit from the feature which
> (again, for me) totally eclipses the only very small regret that ::class
> looks like a class constant lookup.  That syntactical point could have gone
> either way, but I feel like the accepted syntax is still a good choice.

I have found this feature to be useful as well. The essence of this
feature is good, but I feel like the implementation is unfortunate.

> Your example above might attempt to cause some mis-direction to the reader
> of the code a bit because you have clearly defined a symbol (function)
> called "bar", yet you're still name-expanding a class called "bar", which
> technically could be living in the same namespace in a different file
> covered by an autoloader.  bar::class still does actually mean foo\bar the
> class, not the function.
>
> <?php
> namespace foo;
> function bar() {}
> class bar {}
> var_dump(bar::class); // string(7) "foo\bar"
> $b = new bar;
> var_dump(get_class($b));

bar::class does not necessarily mean `foo\bar` the class; it just does
a string expansion. In my opinion it should have been restricted to
only classes and interfaces (or other things like them) since that's
what the RFC and syntax intends, but not what it actually does.

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

Reply via email to