class Colors { const RED = '#FF0000'; const GREEN = '#00FF00'; const BLUE = '#0000FF'; } $reflectionClass = new ReflectionClass('Colors'); $constants = $reflectionClass->getConstants(); foreach ($constants as $name => $value) { echo $name . ' => ' . $value . '
'; }
RED => #FF0000 GREEN => #00FF00 BLUE => #0000FFIn this example, the ReflectionClass is used to retrieve all of the constants declared inside the Colors class. The getConstants() method is called on the reflection object to get an associative array where keys represent constant names and values represent their values. Finally, we loop through the array and display each constant. The package library may not be determined from this functionality alone.