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.
Thanks
The static keyword is used to declare properties and methods of a class as static. Static properties and methods can be used without creating an instance of the class. The static keyword is also used to declare variables in a function which keep their value after the function has ended.
The reflection class is used to get information about the current state of the application. It's called reflection, because it looks at it's self, and can tell you information about the program your running, at run time.
Static class is used for a single instance of that class whereas instantiated class is used when more than one instance is required. Static class contains static variables and static methods whereas instantiated class contains non-static variables and non-static methods.
Introduction to PHP static methods and properties PHP allows you to access the methods and properties in the context of a class rather than an object. Such methods and properties are class methods and properties. Class methods and class properties are called static methods and properties.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With