Let’s say I have this class:
class Example {
public static $FOO = array('id'=>'foo', 'length'=>23, 'height'=>34.2);
public static $BAR = array('id'=>'bar', 'length'=>22.5, 'height'=>96.223);
}
How could I use reflection to get a list of the static fields? (Something like array(‘$FOO’, ‘$BAR’)?)
You’ll want to use [
ReflectionClass][1]. ThegetProperties()function will return an array ofReflectionPropertyobjects. TheReflectionPropertyobject have aisStatic()method which will tell you whether the property is static or not and agetName()method that return the name.Example: