PHP: rfc:class_name_literal_on_object
DRANK

IntroductionThe Foo\Bar::class syntax has been introduced in PHP 5.5 to allow fetching a class name as a string, in a way that respects context-dependent name resolution rules and is understood by IDEs. As it is syntactically similar to a class constant access, programmers intuitively expect the syntax $object::class to work as well and provide the same result as get_class($object). This RFC proposes to allow that syntax.The original rationale for not allowing the $object::class syntax was that Foo\Bar::class is resolved at compile-time, which is not possible for $object::class. However, this premise is already incorrect for two cases: First, static::class is always resolved at runtime, equivalent to get_called_class(). Second, self::class and parent::class are also sometimes resolved at runtime, for example in closures.Overall I think that $object::class has a well-defined meaning, and programmers familiar with the Foo\Bar::class syntax generally expect it to be available by symmetry…

wiki.php.net
Related Topics: PHP