Kod klasy
namespace Batman; abstract class Enum { final public function __construct() { throw new \ErrorException('Can\'t create object from enum'); } { if(self::$_consts === null) { $class = get_called_class(); if($class == __CLASS__) { throw new \BadMethodCallException('You can\'t access constants from Enum class'); } $reflection = new \ReflectionClass($class); self::$_consts = $reflection->getConstants(); } return self::$_consts; } { } { } }
Przykład użycia
class UserStatus extends \Batman\Enum { const DELETED = -1; const BLOCKED = 0; const ACTIVE = 1; }
Download, issue tracker i całą resztę znajdziecie na githubie.