Before PHP 5.3 I was using the following home-made function to create enums :
function enum()
{
for($enums = func_get_args(), $enum = reset($enums), $i = 1; $enum; $enum = next($enums), ++$i)
{
if(defined($enum)) throw new Exception($enum.' is already defined.');
else define($enum, $i);
}
} // enum()
And then :
enum('CONST0', 'CONST1', 'CONST2', ...);
With php 5.3 I can do that using const instead of define to benefit from namespaces. Is there a way I could modify this function to make it use the const keyword ?
Also I'm only using 5.3 to make my code look cleaner, if there must be a performance impact (i.e. using eval or stuffs like that), I'll stick with the good old define.
I've already looked at this question : PHP and Enumerations but I didn't find what I'm looking for.