Value listing

Both Pure Enums and Backed Enums implement an internal interface named UnitEnum. UnitEnum includes a static method cases(). cases() returns a packed array of all defined Cases in the order of declaration.

<?php
Suit
::cases();
// Produces: [Suit::Hearts, Suit::Diamonds, Suit::Clubs, Suit:Spades]
?>

Manually defining a cases() method on an Enum will result in a fatal error.

User Contributed Notes

There are no user contributed notes for this page.
PHP8中文手册 站长在线 整理 版权归PHP文档组所有