I was trying to determine how to get a var_dump of constants that are within an interface. Thats right, not using any classes but the interface itself.
Along my travels I found it quite interesting that the ReflectionClass along with a direct call to the interface will also dump its constants. Perfect!!!!
This was using PHP 5.3.1 and my example as below:-
// Programmatic Level
const DEBUG_MODE_ACTIVE = FALSE;
const PHP_VERSION_REQUIREMENT = "5.1.2";
$oClass = new ReflectionClass ('MyConstants');
$array = $oClass->getConstants ();
what you would get from the command line:-
["PHP_VERSION_REQUIREMENT"]=> string(5) "5.1.2"
But as you can see this can work quite well to your advantage in many ways so I truely hope this helps someone else with a similar headache in the future to come!
ReflectionClass::getConstants — Gets constants
Gets defined constants from a class.
This function is currently not documented; only its argument list is available.
This function has no parameters.
An array of constants. Constant name in key, constant value in value.
- ReflectionClass::getConstant() - Gets defined constant