Created
June 12, 2015 14:26
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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