Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rikudousage/php-enums
Yet another implementation of enums in php
https://github.com/rikudousage/php-enums
Last synced: about 1 month ago
JSON representation
Yet another implementation of enums in php
- Host: GitHub
- URL: https://github.com/rikudousage/php-enums
- Owner: RikudouSage
- License: wtfpl
- Created: 2018-05-30T19:43:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-03T14:01:44.000Z (almost 5 years ago)
- Last Synced: 2024-08-18T07:29:36.612Z (3 months ago)
- Language: PHP
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Enums
This is yet another PHP enum implementation.
What is so different about this one? It uses trait which solves one problem all the
other implementations I've seen have - extending some base enum class.All the enums return the same instance for the same enum, so you can check for equality
(`===`) and the result is true.The constructor is made private, so you cannot directly construct an instance via
`new` keyword (but you can create an constructor in your class and make it public
if you need to, but I advise against it).Every internal method is made private so you cannot extend the enum (well, you can
but it would be useless).```php
getValue(); // echoes "SomeCoolValue"
```The methods you create have a value that you give them:
```php
getValue(); // echoes 1
```## Some caveats
- the trait caches the objects based on value, meaning that if you create
two enum values (static methods) with same value, they will return the same object,
e.g. they will return true for equality test```php