Just jumped out from java to write small thing in php, so I've started like enum Roles {
and remembered that there's no "enum" in php, so I've made my small wrapper
<?php
class Enum {
public static function values() {
return array_values(self::keyValues());
}
public static function keys() {
return array_keys(self::keyValues());
}
public static function keyValues() {
try {
$rc = new \ReflectionClass(get_called_class());
} catch (\ReflectionException $e) {
error_log($e->getMessage());
}
return $rc->getConstants();
}
}
class MyEnum extends Enum {
public CONST SOME = 1;
public CONST ANOTHER = 2;
}
var_dump(MyEnum::keys());