forked from xp-framework/xp-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
core.enum
Alex Kiesel edited this page Jun 7, 2012
·
6 revisions
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.
Here's some more information on enums in the XP framework:
- http://news.xp-framework.net/article/222/2007/11/12/Enum_usecases__Replace_switch_case_blocks
- http://news.xp-framework.net/article/207/2007/07/29/Enum_usecases__Profiling
- http://news.xp-framework.net/article/199/2007/07/05/EASC_and_enum_types
Enums were first introduced in July 2007 within xp-framework/rfc#132 .