I am wanting to use reflection to obtain a list of the constants defined by a class in PHP.
Currently using reflection I can get a list of the constants, but this also i
By default, PHP has no function I'm aware of that would already remove the parent classes and interfaces constants. So you would need to do that your own:
$reflection = new ReflectionClass('Bar');
$buffer = $reflection->getConstants();
foreach (
array($reflection->getParentClass())
+ $reflection->getInterfaces()
as $fill
) {
$buffer = array_diff_key($buffer, $fill->getConstants());
}
The result in $buffer
is the array you are looking for:
Array
(
[CHILD_CONST] => child
[BAR_CONST] => bar_const
)