Skip to content

Instantly share code, notes, and snippets.

@gargoyle
Created October 24, 2012 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gargoyle/3944988 to your computer and use it in GitHub Desktop.
Save gargoyle/3944988 to your computer and use it in GitHub Desktop.
protected static function getConstantValues($prefix = '')
{
$refl = new ReflectionClass(get_called_class());
$allConstants = $refl->getConstants();
if ($prefix != '') {
$prefixLength = strlen($prefix);
$filteredList = array();
foreach ($allConstants as $key => $value) {
if (substr($key, 0, $prefixLength) == $prefix) {
$filteredList[$key] = $value;
}
}
return $filteredList;
} else {
return $allConstants;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment