SPL Types
PHP Manual

The SplEnum class

(No version information available, might only be in SVN)

简介

SplEnum gives the ability to emulate and create enumeration objects natively in PHP.

类摘要

SplEnum extends SplType {
/* Constants */
const NULL __default = null ;
/* 方法 */
public array getConstList ([ bool $include_default = false ] )
/* 继承的方法 */
SplType::__construct ([ mixed $initial_value [, bool $strict ]] )
}

预定义常量

SplEnum::__default

范例

Example #1 SplEnum usage example

<?php
class 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

Table of Contents


SPL Types
PHP Manual