枚举值清单
无论是纯粹枚举还是回退枚举,都实现了一个叫 UnitEnum 的内部接口。
UnitEnum
包含了一个静态方法:
cases()
。
按照声明中的顺序,cases()
返回了打包的 array,包含全部定义的条目。
<?php
Suit::cases();
// 产生: [Suit::Hearts, Suit::Diamonds, Suit::Clubs, Suit::Spades]
?>
为 Enum 手动定义 cases()
方法会导致 fatal 错误。

User Contributed Notes
There are no user contributed notes for this page.
备份地址:http://www.lvesu.com/blog/php/language.enumerations.listing.php