PHP and Enums
Posted
by Henrik Paul
on Stack Overflow
See other posts from Stack Overflow
or by Henrik Paul
Published on 2008-10-31T18:51:14Z
Indexed on
2010/06/06
18:22 UTC
Read the original article
Hit count: 286
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?
© Stack Overflow or respective owner