Php/docs/class.splenum

提供:Dev Guides
< Php
移動先:案内検索

(PECL spl_types >= 0.1.0)

はじめに

SplEnum は、PHP ネイティブで列挙型のオブジェクトを作成します。


クラス概要


SplEnum extends SplType {

/* 定数 */

const NULL __default = null

/* メソッド */

public getConstList ([ bool $include_default = false ] ) : array

/* 継承したメソッド */

SplType::__construct ([ mixed $initial_value [, bool $strict ]] )

}

定義済み定数

SplEnum::__default


例1 SplEnum の使用例

<?phpclass Month extends SplEnum {    const __default = self::January;        const January = 1;    const February = 2;    const March = 3;    const April = 4;    const May = 5;    const June = 6;    const July = 7;    const August = 8;    const September = 9;    const October = 10;    const November = 11;    const December = 12;}echo new Month(Month::June) . PHP_EOL;try {    new Month(13);} catch (UnexpectedValueException $uve) {    echo $uve->getMessage() . PHP_EOL;}?>

上の例の出力は以下となります。


6
Value not a const in enum Month

目次