Download the PHP package bonndan/phpenums without Composer
On this page you can find all versions of the php package bonndan/phpenums. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bonndan/phpenums
More information about bonndan/phpenums
Files in bonndan/phpenums
Package phpenums
Short Description An experimental Enum implementation for PHP7
License
Informations about the package phpenums
PHP Enums
Yet another implementation of Enums in PHP. The difference to most other implementations is that the implemetation is very close to Java. Static properties are used, but like in Java they are real instances of the Enum providing all methods etc:
So you can use static typing:
What are the drawbacks?
-
Each enum has to be registered (unless static constructors arrive in PHP). The reason is that static properties can only have scalar values as default.
- You need to annotate all static props in order to get your IDE working with it, but at least this works.
-
No default values usable. At "compile time" $BANANA is not yet an instance. However you can use null as default value.
- Use/import is not possible, i.e. you cannot just write $BANANA.
Advanced use
Each enum instance can obtain its own properties by implementing the magic invoke method.