Skip to content
Alex Kiesel edited this page May 27, 2012 · 6 revisions

Type-safe enumerations

Often there is the necessity to define functionality based on a set of values. If you have experience in C, you may have seen typedef enum { WHITE, BLACK, YELLOW } color_t; before. In PHP, one could write something like define('WHITE', 0); and define('BLACK', 1); which is pretty much what the C version does. The problem with these approaches are that they are not type-safe, and functionality needs to be attached by using switch or if-else cascades.

Further reading

Here's some more information on enums in the XP framework:

From our blog

  • [entry://222 Enum usecases: Replace switch/case blocks]
  • [entry://207 Enum usecases: Profiling]
  • [entry://199 EASC and enum types]

History

Enums were first introduced in July 2007 within [rfc://0132 RFC 0132].

Clone this wiki locally