Closed jdecool closed 5 years ago
Hi @jdecool,
Enumerators are public by definition. As PHP doesn't support real enumeration types this library emulates them as much as possible. For that it's using class constants as workaround.
Here are some reasons why enumerators are public:
MyEnum::ENUMERATOR
MyEnum::ENUMERATOR()
private class MyEnum extends Enum
).Thanks for your answer.
But I not agree with you.
The Enum should be encapsulate in the object
(accessible with MyEnum::ENUMERATOR()->getValue()
) and should not directly acces the constant MyEnum::ENUMERATOR
used to build it.
Hi @jdecool,
This again is an implementation detail because of the lag of build-in enum support in PHP. An enumerator is a constant definition. This implementation uses objects for this case and makes the defined enumerator value and name accessable. On a perfect implementation both information would be available on compile time but that's not possible here as this library emulates the enumeration type as much as possible. What I want to say is that an enumerator value is just one possible value of a self defined enumeration type. Which makes it public by definition.
Actually the
Enum
class only managepublic
constant.I think it's interesting to manage constant independently of the property visibility.
When I create an Enum, I don't want the developer know how it works internally, so I don't want to expose the constant I used to build it.
Should you open to a PR to make this change ?