Skip to content

Instantly share code, notes, and snippets.

@mcunha98
Created December 30, 2020 12:52
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 mcunha98/48e513741cc9c0265b92eafa62e91804 to your computer and use it in GitHub Desktop.
Save mcunha98/48e513741cc9c0265b92eafa62e91804 to your computer and use it in GitHub Desktop.
Check if current class has constant/enumeration based on value
class Assets
{
const ASSETS_BANNER = 'banner';
const ASSETS_BLOG = 'blog';
const ASSETS_TEMPLATE = 'template';
private static $constants;
public static function isConstant($value)
{
if (!isset(self::$constants))
{
$reflect = new ReflectionClass(__CLASS__);
self::$constants = $reflect->getConstants();
}
return in_array($value, self::$constants);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment