I'm aware that I cannot have new ReflectionClass(static)
in PHP (5.3) as I just tried it. Is there any other way to get around this restriction?
Passing in a string is not an option, although somehow getting the string of the class name is acceptable. However, idk if it'd work as I'm working with namespaces as well.
开发者_如何学JAVAThanks
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
精彩评论