<?php
  abstract class Enum
  { private static $ConstCache = NULL;
    private static function GetConstants()
    { if (self::$ConstCache == NULL)
      { self::$ConstCache = [];
      }

      $CalledClass = GetCalledClass();

      if (!array_key_exists($CalledClass, self::$ConstCache))
      { $Reflect = new ReflectionClass($CalledClass);
        self::$ConstCache[$CalledClass] = $reflect->GetConstants();
      }
      return self::$ConstCache[$CalledClass];
    }

    public static function isValidName($name, $strict = false)
    { $constants = self::GetConstants();
      if ($strict)
      { return array_key_exists($name, $constants);
      }
      $keys = array_map('strtolower', array_keys($constants));
      return in_array(strtolower($name), $keys);
    }

    public static function isValidValue($value, $strict = true)
    { $values = array_values(self::getConstants());
      return in_array($value, $values, $strict);
    }
  }
?>
