SplEnum

用于定义枚举一个集合,规范化枚举数据。

相关class位置

  • SplEnum
    • namespace: EasySwoole\Spl\SplEnum

SplEnum相关方法

方法列表

方法名称参数说明备注
__construct$val构造函数
getName获取定义常量的键
getValue获取定义常量
isValidNamestring $name查找常量的键值是否有效
isValidValue$val查找常量的值是否有效
getEnumList获取枚举集合
getConstants获取枚举集合

基本使用

  1. /**
  2. *
  3. * User: luffyQAQ
  4. * Date: 2019/10/16 17:08
  5. * Email: <1769360227@qq.com>
  6. */
  7. include "./vendor/autoload.php";
  8. class Month extends \EasySwoole\Spl\SplEnum {
  9. const JANUARY = 1;
  10. const FEBRUARY = 2;
  11. const MARCH = 3;
  12. const APRIL = 4;
  13. const MAY = 5;
  14. const JUNE = 6;
  15. const JULY = 7;
  16. const AUGUST = 8;
  17. const SEPTEMBER = 9;
  18. const OCTOBER = 10;
  19. const NOVEMBER = 11;
  20. const DECEMBER = 12;
  21. }
  22. $month = new Month(1);
  23. var_dump($month->getName());
  24. var_dump($month->getValue());
  25. var_dump(Month::isValidName('JANUARY'));
  26. var_dump(Month::isValidValue(1));
  27. var_dump( Month::getEnumList());