joaorbrandao / phenum
PHP enums made easy.
Installs: 11
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/joaorbrandao/phenum
Requires
- php: >=7.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- phpunit/phpunit: 8.*
This package is auto-updated.
Last update: 2025-09-29 01:33:16 UTC
README
This package creates a simple way of creating PHP enums (one more!). Your IDE will detect them without using DocBlocks. In the end, it's all about PHP constants!
Installing
composer require joaorbrandao/phenum
Usage
Create an Enum
- Create a class.
- Extend the
Enum
class. - Use the
Enumerable
trait. - Define PHP constants as needed.
<?php namespace Acme; use Joaorbrandao\Phenum\Classes\Enum; use Joaorbrandao\Phenum\Traits\Enumerable; class Peripheral extends Enum { use Enumerable; const MOUSE = 'mouse'; const KEYBOARD = 'keyboard'; }
Use it
We're talking about PHP constants, so:
<?php $mouse = Peripheral::MOUSE;
But in case you need some help like getting all defined values, the first, last, etc:
<?php $first = Peripheral::first(); // 'mouse' $last = Peripheral::last(); // 'keyboard' $exists = Peripheral::exists('mouse'); // true
License
phenum is an open-source package licensed under the MIT license.