title: SplEnum meta:

  • name: description content: EasySwoole SplEnum
  • name: keywords content: swoole|swoole extension|swoole framework|easyswoole,SplEnum

Use

Used to define a collection of enumerations and normalize enumeration data.

SplEnum related methods

Method list

Method Name Parameters Description Notes
__construct $val Constructor
getName Get the key that defines the constant
getValue Get defined constants
isValidName string $name Finding if the constant’s key value is valid
isValidValue $val Finding if the value of a constant is valid
getEnumList Get Enumeration Collection
getConstants Get Enumeration Collection

how to use

  1. /**
  2. *
  3. * User: zs
  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());