PHP implementation of Enum
<?phpuseEnum\AbstractEnum;
class Day extends AbstractEnum
{
constSUNDAY = 0;
constMONDAY = 1;
constTUESDAY = 2;
constWEDNESDAY = 3;
constTHURSDAY = 4;
constFRIDAY = 5;
constSATURDAY = 6;
protectedstatic$default = self::SUNDAY;
publicfunctiongetLabel()
{
returndate('l', strtotime(sprintf('Sunday + %d Days', $this->getValue())));
}
}
$defaultDay = newDay();
echo$defaultDay->getValue();
// 0echo$defaultDay->getLabel();
// Sunday$monday = newDay(Day::MONDAY);
echo$monday->getValue();
// 1echo$monday;
// 1print_r(Day::getValues());
// Array ( [SUNDAY] => 0 [MONDAY] => 1 [TUESDAY] => 2 [WEDNESDAY] => 3 [THURSDAY] => 4 [FRIDAY] => 5 [SATURDAY] => 6 )echo$monday->getLabel();
// Mondayprint_r(Day::getLabels());
// Array ( [0] => Sunday [1] => Monday [2] => Tuesday [3] => Wednesday [4] => Thursday [5] => Friday [6] => Saturday )