Static ReflectionClass in PHP?

I know that I cannot have new ReflectionClass(static) in PHP (5.3) since I just tried. Is there any other way around this limitation?

Passing a string is not an option, although getting a string of the class name is acceptable. However, idk if it will work when I work with namespaces.

thanks

+4
source share
1 answer

You can use get_called_class() to get a string containing the called class.

 class Foo { public static function getReflection() { return new ReflectionClass(get_called_class()); } } class Bar extends Foo {} $reflectBar = Bar::getReflection(); // reflectBar now holds a ReflectionClass instance for Bar 
+15
source

All Articles