generated at
PHPのEnum型
PHP v8.1から入った




それ以前は、ハックで自作Enumを作る感じになってた
php
final class ArrangeType { const ENUM = [ 'size' => 'size', 'color' => 'color', 'shape' => 'shape', 'ng' => 'ng', ]; private $scalar; // genericがないので型を書けない function __construct($key) { if (!static::isValidValue($key)) { throw new \InvalidArgumentException; } $this->scalar = self::ENUM[$key]; } static function isValidValue($key) { return array_key_exists($key, self::ENUM); } function __toString() { return $this->scalar; } }