I know that PHP doesn't have native Enumerations. But I have become accustomed to them from the Java world. I would love to use enums as a way to give predefined values which IDEs' auto completion features could understand.
Constants do the trick, but there's the namespace collision problem and (or actually because) they're global. Arrays don't have the namespace problem, but they're too vague, they can be overwritten at runtime and IDEs rarely (never?) know how to autofill their keys.
Are there any solutions/workarounds you commonly use? Does anyone recall whether the PHP guys have had any thoughts or decisions around enums?
There is a native extension, too. The SplEnum
http://www.php.net/manual/en/class.splenum.php
The most common solution that I have seen to enum's in PHP has been to create a generic enum class and then extend it. You might take a look at this.
UPDATE: Alternatively, I found this from phpclasses.org.
This is my take on "dynamic" enum... so that i can call it with variables, ex. from a form.
look at updated verison below this codeblock...
UPDATE: Better way of doing it...
Call with
I like enums from java too and for this reason I write my enums in this way, I think this is the most similiar behawior like in Java enums, of course, if some want to use more methods from java should write it here, or in abstract class but core idea is embedded in code below
Stepping on the answer of @Brian Cline I thought I might give my 5 cents