Hi Ralph,

You persuade me. :)

The SOMETHING::class syntax looked wired to me because I didn't understand it.

However, the SOMETHING::class syntax might be considered as a reference to a predefined class constant and in this case it looks quite consistent. I suggest to reflect it in RFC and documentation (if we agree to include it in release) to avoid future misunderstanding.

Also I would expect SOMETHING::class to work in all cases where class constants work. e.g. self::class, parent::class, static::class, $obj::class. To do it for parent, static and $obj you'll probably need a new opcode - ZEND_FETCH_CLASSNAME that must be very similar to ZEND_FETCH_CLASS. May be it's possible to do the same using ZEND_FETCH_CONSTANT, but I don't think it makes sense to complicate the existing opcode.

SOMETHING::class must be consistent with traits.

In case all the above works, I say +1 and even may help with implementation.

Finally, may be SOMETHING::__CLASS__ is a bit more clear than SOMETHING::class.

Thanks. Dmitry.



On 09/14/2012 12:51 AM, Ralph Schindler wrote:

I think the syntax is wired.
Instead of classname::class I would prefer something like
class(classname).


I am not a big fan of the syntax class(ShortClass\Name) as to me it
looks like a function call.

Personally, I like drawing parallels from the same languages that I
think helped shaped PHP's object-model.  In this case, the Java has a
similar enough feature where Type.class returns a class object (in our
case we just need to return a string of the FQ class name).

Your suggestion is similar to that of, I think, C# where
typeof(SomeClassName) would return a reflection-like/type object where
you could get the FullName():

http://msdn.microsoft.com/en-us/library/58918ffs%28v=vs.71%29.aspx

I could go either way, at this point (after the April discussion on the
matter), I had not really given much thought to class() lang. construct.

Personally, ::class feels a bit better to me in that the context feels
more "compile-time", like __CLASS__, and the NS resolutions, than does
class() that you suggest.

 From a wider perspective, I've seen these variations in the wild:

class Foo {
   const CLASSNAME = __CLASS__;
   // or
   const _class = __CLASS__;
}

Which allows for the usage:

   Foo::CLASSNAME;

for example.

FWIW, both reusing the class() keyword making it BC, which is something
I like.

-ralph




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

Reply via email to