SplArray

用途

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

如何使用

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: root
  5. * Date: 19-1-9
  6. * Time: 上午10:10
  7. */
  8. require './vendor/autoload.php';
  9. class Month extends \EasySwoole\Spl\SplEnum {
  10. const JANUARY = 1;
  11. const FEBRUARY = 2;
  12. const MARCH = 3;
  13. const APRIL = 4;
  14. const MAY = 5;
  15. const JUNE = 6;
  16. const JULY = 7;
  17. const AUGUST = 8;
  18. const SEPTEMBER = 9;
  19. const OCTOBER = 10;
  20. const NOVEMBER = 11;
  21. const DECEMBER = 12;
  22. }
  23. $month = new Month(1);
  24. echo $month->getName();
  25. /**
  26. * 输出结果:
  27. * JANUARY
  28. */

核心对象方法

核心类:EasySwoole\Spl\SplEnum。

__construct

构造函数

  • mixed $val 查找的值

final public function __construct($val)

getName

获取定义常量的键

final public function getName():string

getValue

获取定义常量

final public function getValue()

isValidName

查找常量的键值是否有效

  • string $name 查找常量的键值

final public static function isValidName(string $name):bool

isValidValue

查找常量的值是否有效

  • mixed $val 查找常量的值

final public static function isValidValue($val)

getEnumList

获取枚举集合

final public static function getEnumList():array

getConstants

获取枚举集合

private final static function getConstants():array