Closed procraste closed 5 years ago
Hi @procraste,
First thanks for being interested in my small library :)
I'm not sure I understand your question but I'll respond from how I got it.
The ordinal attribute of an enumerator is an internal (private
) property.
The internal property value is either not defined NULL
or it is the ordinal number of the enumerator as defined in the enumeration class. The reason why the internal property number can be undefined is simply because detecting the ordinal number takes CPU resources and so gets detected only in case it gets used.
Long story short:
getOrdinal()
. This takes care of the internal behavior and returns the ordinal number in all cases.Hi there,
Thanks for your quick reply !
(...) the internal property number can be undefined (...) and so gets detected only in case it gets used.
Great ! This is exactly what i was missing !
I didn't understand why sometimes i had the ordinal and sometimes not ... I should have dig more into the code to fully understand it is calculated when needed.
Thanks again !
Hi there, I'm quite new to dev. I came across your PHP-ENUM in a stack overflow post ... I wanted to use it in a small project. I've some difficulties to understand how the ordinal attribute is set. In fact i made a small class that extends ENUM and create some objects via the static method. all the objects had a NULL ordinal attribute .... That was logical ! But suddenly a new object got "2" as ordinal attribute ... The new one also got a "2". Strange. Could you provide some explanation about the ordinal attribute ? Perhaps add an example to the readme. Hope this make sense. Thanks anyway.