Several other PHP Enum libraries implement the multiton pattern so that only a single instance of a particular Enum value is ever returned, thereby allowing strict comparisons. Is this a feature you would be interested in adding to this library?
$admin = UserType::fromValue(UserType::Administrator);
// Instead of:
$admin->is(UserType::Administrator()); // true
// One could also check equality directly:
$admin === UserType::Administrator(); // true
The implementation would be quite simple, and could even use WeakReferences if the requirements were increased to PHP 7.4.
Several other PHP Enum libraries implement the multiton pattern so that only a single instance of a particular Enum value is ever returned, thereby allowing strict comparisons. Is this a feature you would be interested in adding to this library?
The implementation would be quite simple, and could even use WeakReferences if the requirements were increased to PHP 7.4.
(See https://github.com/Elao/PhpEnums#compare for an example.)