vladdesv / simple-enum
This package is abandoned and no longer maintained.
No replacement package was suggested.
Dead simple enum
1.2.0
2020-12-01 20:32 UTC
Requires
- php: >=5.3
Requires (Dev)
- phpunit/phpunit: 4.0
README
SimpleEnum
Dead simple PHP enum. This thing runs on PHP 5.3, heck maybe even PHP 5.1.2*, so just yoink the files if you need it for your Legacy project.
* This enum uses the Reflection class, which was introduced in PHP 5.1.2
Why?
I come from C-like languages with proper enums. Why is there no such simple, built-in, proper, enum in PHP?
The SplEnum looks promising, but has some oddities with its implementation. As an added bonus, it might not work for your setup.
Other third-party alternatives (see this, this, this, and this for instance) are overly complicated for my needs. This should probably solve it for most of my use cases.
Example
<?php use SimpleEnum\Enum; class MyEnum extends Enum { const foo = 1; const bar = 2; const baz = 3; } $myEnum = new MyEnum(MyEnum::foo); assert($myEnum->value() === MyEnum::foo); assert($myEnum->equals(new MyEnum(1)));
Installation
composer require vladdesv/simple-enum
License
MIT © Vladimirs Nordholm