Laravel has a
I disagree with the accepted answer here. I feel that enums can be very useful for this kind of thing. I prefer to treat enums as types, and implement the methods you need on the Enum base class to give you the functionality you need such as getting a dictionary.
My simple example below:
abstract class PhoneType extends Enum {
const Cell = "Cellular";
const Home = "Home";
const Work = "Work";
}
abstract class Enum {
static function getKeys(){
$class = new ReflectionClass(get_called_class());
return array_keys($class->getConstants());
}
}
Example usage:
PhoneType::getKeys();
See PHP and Enumerations for further details and a more in depth example.