Enum 枚举

枚举基础

枚举是在类、类常量基础上的约束层, 目标是提供一种能力:定义包含可能值的封闭集合类型。

<?php
enum Suit
{
case
Hearts;
case
Diamonds;
case
Clubs;
case
Spades;
}

function
do_stuff(Suit $s)
{
// ...
}

do_stuff(Suit::Spades);
?>

详情参阅枚举章节。

类型转换

enum 转换为 object 不会有变化。 将 enum 转换为 array, 纯粹枚举会创建单个 name 键的数组; 回退枚举创建带 namevalue 键的数组。 其他类型转换都会导致错误。

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top