Dan Cryer wrote on 22/09/2015 16:06:
C#'s enums seem a good model to follow.
It's worth pointing out that C#'s enums are basically the same as C's - a typedef over int with a handful of helper methods in the standard library. They don't even range-check on assignment, so that a "weekday" variable can be given the value 42. [1]
This is very different to Java or Python, where enums are a special kind of object, strictly typed, and comparable only with themselves. (Python classes can relax these constraints by overloading various operators.)
Java's enums have no intrinsic "value", but can have arbitrary fields set up by a constructor. They do have an ordinal() method, but "Most programmers will have no use for this method." The toString() method returns the name of the Enum constant. [2][3]
Python's enums have both a name and a value, but the value can be of any type. Most of the examples in the manual do use integer values, though, and there is a suggestion of how to implement auto-numbering. [4]
References: [1] https://msdn.microsoft.com/en-us/library/cc138362.aspx [2] https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html [3] http://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html [4] https://docs.python.org/3/library/enum.html Regards, -- Rowan Collins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php