Skip to content

Instantly share code, notes, and snippets.

@lsloan
Created June 12, 2015 14:26
Show Gist options
  • Save lsloan/7ea46c9831b55e70813c to your computer and use it in GitHub Desktop.
Save lsloan/7ea46c9831b55e70813c to your computer and use it in GitHub Desktop.
My subclass of PHP's enum class, SplEnum, from the spl_types extension on PECL. Adds a method to indicate whether an enum has a desired key.
<?php
class SplEnumPlus extends \SplEnum {
static function hasKey($key) {
$foundKey = false;
try {
$enumClassName = get_called_class();
new $enumClassName($key);
$foundKey = true;
} finally {
return $foundKey;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment