Edit report at https://bugs.php.net/bug.php?id=54417&edit=1
ID: 54417 Comment by: aigors at inbox dot lv Reported by: webseiten dot designer at googlemail dot com Summary: Add string casting support for class/interface names Status: Open Type: Feature/Change Request Package: Class/Object related Operating System: N/A PHP Version: Irrelevant Block user comment: N Private report: N New Comment: I find this idea very good in cases when you want to find all usages of the class over all project inside your IDE. When using class name as hardcoded string this isn't possible. Also in PHP 5.3 possible workaround for this missing feature is to create method "static function __CLASS__() {return get_called_class();}" in all base classes which is extended by other classes. Sure it doesn't help for the interfaces. Previous Comments: ------------------------------------------------------------------------ [2011-03-29 17:32:08] webseiten dot designer at googlemail dot com Description: ------------ Please add a way to get the fully qualified class or interface name without the need to create an object. While it is possible to declare a static variable in classes as a workaround, this will not work with interfaces, as you can't declare members inside them. A common trick I've seen is to use a constant: namespace Foo\Bar; interface A { const __NAME = __CLASS__; } factory(Bar\A::__NAME); // calls factory with '\Foo\Bar\A' Though this won't work with inheritance. The magic __NAMESPACE__ constant is also no help when importing namespaces. I propose to use the __CLASS__ keyword to implement such a feature, as it is not allowed to have a class constant of this name: namespace Foo\Bar { interface A {} } namespace Orange\Banana { use Foo\Bar; echo Bar\A::__CLASS__; // should print "Foo\Bar\A" } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=54417&edit=1