PHPackages                             vicgutt/php-enhanced-enum - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. vicgutt/php-enhanced-enum

ActiveLibrary

vicgutt/php-enhanced-enum
=========================

Enhances PHP's native enums with convenient methods

v0.1.0(3y ago)01.7k—0%MITPHPPHP ^8.1

Since Nov 5Pushed 3y ago1 watchersCompare

[ Source](https://github.com/VicGUTT/php-enhanced-enum)[ Packagist](https://packagist.org/packages/vicgutt/php-enhanced-enum)[ Docs](https://github.com/vicgutt/php-enhanced-enum)[ RSS](/packages/vicgutt-php-enhanced-enum/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Enhances PHP's native enums with convenient methods
===================================================

[](#enhances-phps-native-enums-with-convenient-methods)

[![GitHub Tests Action Status](https://github.com/vicgutt/php-enhanced-enum/actions/workflows/run-tests.yml/badge.svg)](https://github.com/vicgutt/php-enhanced-enum/actions/workflows/run-tests.yml)[![GitHub PHPStan Action Status](https://github.com/vicgutt/php-enhanced-enum/actions/workflows/phpstan.yml/badge.svg)](https://github.com/vicgutt/php-enhanced-enum/actions/workflows/phpstan.yml)[![GitHub Code Style Action Status](https://github.com/vicgutt/php-enhanced-enum/actions/workflows/fix-php-code-style-issues.yml/badge.svg)](https://github.com/vicgutt/php-enhanced-enum/actions/workflows/fix-php-code-style-issues.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/7f697f4e88487c2a72a6a6a068f232a1ff94bd56f790f8f7c2ce106a0369580f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f766963677574742f7068702d656e68616e6365642d656e756d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vicgutt/php-enhanced-enum)[![Total Downloads](https://camo.githubusercontent.com/f55e41718db30e6b4c4aeca42e3d1f5fd0bc8cfed2cdb4fc006538df4c8abaf7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f766963677574742f7068702d656e68616e6365642d656e756d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vicgutt/php-enhanced-enum)

---

This package provides you with convenient and single purposed traits and interfaces that aims to independently enhance native PHP enums.

The provided traits are:

- [VicGutt\\PhpEnhancedEnum\\Concerns\\`HasKeys`](/src/Concerns/HasKeys.php)
- [VicGutt\\PhpEnhancedEnum\\Concerns\\`HasValues`](/src/Concerns/HasValues.php)
- [VicGutt\\PhpEnhancedEnum\\Concerns\\`HasEntries`](/src/Concerns/HasEntries.php)
- [VicGutt\\PhpEnhancedEnum\\Concerns\\`IsComparable`](/src/Concerns/IsComparable.php)
- [VicGutt\\PhpEnhancedEnum\\Concerns\\`Enumerable`](/src/Concerns/Enumerable.php)

The provided interfaces are:

- [VicGutt\\PhpEnhancedEnum\\Contracts\\`HasKeysContract`](/src/Contracts/HasKeysContract.php)
- [VicGutt\\PhpEnhancedEnum\\Contracts\\`HasValuesContract`](/src/Contracts/HasValuesContract.php)
- [VicGutt\\PhpEnhancedEnum\\Contracts\\`HasEntriesContract`](/src/Contracts/HasEntriesContract.php)
- [VicGutt\\PhpEnhancedEnum\\Contracts\\`IsComparableContract`](/src/Contracts/IsComparableContract.php)
- [VicGutt\\PhpEnhancedEnum\\Contracts\\`EnumerableContract`](/src/Contracts/EnumerableContract.php)

**Note**: The `Enumerable` trait is a compound of all the available traits and similarly, the `EnumerableContract` interface extends all the other interfaces.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require vicgutt/php-enhanced-enum
```

Usage
-----

[](#usage)

As the package only provides you with traits and interfaces to enhance your enums, you will need to make use of the given trait/interface pair for each of your enums.

Example:

```
use VicGutt\PhpEnhancedEnum\Concerns\Enumerable;
use VicGutt\PhpEnhancedEnum\Contracts\EnumerableContract;

enum MyEnum: string implements EnumerableContract
{
    use Enumerable;

    case CASE1 = 'case1';
    case CASE2 = 'case2';
}
```

From there, you will be able to use any of the provided additional methods.

Traits, interfaces and available methods
----------------------------------------

[](#traits-interfaces-and-available-methods)

We will be using the following example enums throughout this documentation:

```
use VicGutt\PhpEnhancedEnum\Concerns\Enumerable;
use VicGutt\PhpEnhancedEnum\Contracts\EnumerableContract;

/**
 * A "unit enum"
 */
enum MovementsEnum implements EnumerableContract
{
    use Enumerable;

    case ME_TOO;
    case BLACK_LIVES_MATTER;
    case LGBTQ_PLUS;
    case AND_MANY_MANY_MORE;
}

/**
 * An integer typed "backed enum"
 */
enum PromiseEnum: int implements EnumerableContract
{
    use Enumerable;

    case PENDING = 1;
    case RESOLVED = 2;
    case REJECTED = 3;
}

/**
 * A string typed "backed enum"
 */
enum StatusEnum: string implements EnumerableContract
{
    use Enumerable;

    case PENDING = 'pending';
    case SUCCEEDED = 'succeeded';
    case FAILED = 'failed';
}
```

**Note**: The example enums above could each choose to make use of one, all or any of the provided traits and interfaces individually.

### HasKeys

[](#haskeys)

Retrieve the enum's case names.

Example:

```
MovementsEnum::keys(); // ['ME_TOO', 'BLACK_LIVES_MATTER', 'LGBTQ_PLUS', 'AND_MANY_MANY_MORE']
PromiseEnum::keys(); // ['PENDING', 'RESOLVED', 'REJECTED']
StatusEnum::keys(); // ['PENDING', 'SUCCEEDED', 'FAILED']
```

### HasValues

[](#hasvalues)

Retrieve the enum's case values.

Example:

```
MovementsEnum::values(); // ['ME_TOO', 'BLACK_LIVES_MATTER', 'LGBTQ_PLUS', 'AND_MANY_MANY_MORE']
PromiseEnum::values(); // [1, 2, 3]
StatusEnum::values(); // ['pending', 'succeeded', 'failed']
```

**Note**: For "unit enum"s, as they don't technically have values, the `HasValues` trait will use the enum's keys as values. Thefore, the values will always be the same as the keys.

### HasEntries

[](#hasentries)

Retrieve the enum's keys and values.

Example:

```
MovementsEnum::entries(); // ['ME_TOO' => 'ME_TOO', 'BLACK_LIVES_MATTER' => 'BLACK_LIVES_MATTER', 'LGBTQ_PLUS' => 'LGBTQ_PLUS', 'AND_MANY_MANY_MORE' => 'AND_MANY_MANY_MORE']
PromiseEnum::entries(); // ['PENDING' => 1, 'RESOLVED' => 2, 'REJECTED' => 3]
StatusEnum::entries(); // ['PENDING' => 'pending', 'SUCCEEDED' => 'succeeded', 'FAILED' => 'failed']
```

**Note**: For "unit enum"s, as they don't technically have values, the `HasEntries` trait will use the enum's keys as values. Thefore, the values will always be the same as the keys.

### IsComparable::is

[](#iscomparableis)

Checks if a given value is equal to itself.

Example:

```
MovementsEnum::ME_TOO->is(MovementsEnum::ME_TOO); // true
MovementsEnum::ME_TOO->is(MovementsEnum::BLACK_LIVES_MATTER); // false
MovementsEnum::ME_TOO->is('ME_TOO'); // true
MovementsEnum::ME_TOO->is('Me_TOO'); // false
MovementsEnum::ME_TOO->is(123); // false

PromiseEnum::PENDING->is(PromiseEnum::PENDING); // true
PromiseEnum::PENDING->is(StatusEnum::PENDING); // false
PromiseEnum::PENDING->is(1); // true
PromiseEnum::PENDING->is('1'); // false
PromiseEnum::PENDING->is('yolo'); // false

StatusEnum::PENDING->is(StatusEnum::PENDING); // true
StatusEnum::PENDING->is(PromiseEnum::PENDING); // false
StatusEnum::PENDING->is('pending'); // true
StatusEnum::PENDING->is('PENDING'); // false
StatusEnum::PENDING->is(123); // false
```

### IsComparable::isAny

[](#iscomparableisany)

Checks if any of the given values are equal to itself.

Example:

```
MovementsEnum::ME_TOO->isAny([MovementsEnum::ME_TOO]); // true
MovementsEnum::ME_TOO->isAny([MovementsEnum::ME_TOO, MovementsEnum::BLACK_LIVES_MATTER]); // true
MovementsEnum::ME_TOO->isAny(['ME_TOO', MovementsEnum::BLACK_LIVES_MATTER]); // true
MovementsEnum::ME_TOO->isAny(MovementsEnum::BLACK_LIVES_MATTER, 'Me_TOO', 123]); // false

PromiseEnum::PENDING->isAny([PromiseEnum::PENDING]); // true
PromiseEnum::PENDING->isAny([PromiseEnum::PENDING, MovementsEnum::BLACK_LIVES_MATTER]); // true
PromiseEnum::PENDING->isAny([1, MovementsEnum::BLACK_LIVES_MATTER]); // true
PromiseEnum::PENDING->isAny(MovementsEnum::BLACK_LIVES_MATTER, 'PENDING', 123]); // false

StatusEnum::PENDING->isAny([StatusEnum::PENDING]); // true
StatusEnum::PENDING->isAny([StatusEnum::PENDING, MovementsEnum::BLACK_LIVES_MATTER]); // true
StatusEnum::PENDING->isAny(['pending', MovementsEnum::BLACK_LIVES_MATTER]); // true
StatusEnum::PENDING->isAny(MovementsEnum::BLACK_LIVES_MATTER, 'PENDING', 123]); // false
```

### IsComparable::isAll

[](#iscomparableisall)

Checks if all of the given values are equal to itself.

Example:

```
MovementsEnum::ME_TOO->isAll([MovementsEnum::ME_TOO]); // true
MovementsEnum::ME_TOO->isAll([MovementsEnum::ME_TOO, 'ME_TOO']); // true
MovementsEnum::ME_TOO->isAll([MovementsEnum::ME_TOO, 'ME_TOO', MovementsEnum::BLACK_LIVES_MATTER]); // false

PromiseEnum::PENDING->isAll([PromiseEnum::PENDING]); // true
PromiseEnum::PENDING->isAll([PromiseEnum::PENDING, 1]); // true
PromiseEnum::PENDING->isAll([PromiseEnum::PENDING, 1, MovementsEnum::BLACK_LIVES_MATTER]); // false

StatusEnum::PENDING->isAll([StatusEnum::PENDING]); // true
StatusEnum::PENDING->isAll([StatusEnum::PENDING, 'pending']); // true
StatusEnum::PENDING->isAll([StatusEnum::PENDING, 'pending', MovementsEnum::BLACK_LIVES_MATTER]); // false
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

If you're interested in contributing to the project, please read our [contributing docs](https://github.com/vicgutt/php-enhanced-enum/blob/main/.github/CONTRIBUTING.md) **before submitting a pull request**.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Victor GUTT](https://github.com/vicgutt)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

25

—

LowBetter than 40% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1232d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/88ae8f0fc220c28b6b5effd3b319d26ee05cf51066c42d72b606d57dad308ae6?d=identicon)[vicgutt](/maintainers/vicgutt)

---

Top Contributors

[![VicGUTT](https://avatars.githubusercontent.com/u/39224143?v=4)](https://github.com/VicGUTT "VicGUTT (5 commits)")

---

Tags

enumphpphpenum

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/vicgutt-php-enhanced-enum/health.svg)

```
[![Health](https://phpackages.com/badges/vicgutt-php-enhanced-enum/health.svg)](https://phpackages.com/packages/vicgutt-php-enhanced-enum)
```

###  Alternatives

[kongulov/interact-with-enum

Trait for convenient use of ENUM in PHP

3049.0k2](/packages/kongulov-interact-with-enum)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2515.8k](/packages/iteks-laravel-enum)[ducks-project/spl-types

Polyfill Module for SplType PHP extension. This extension aims at helping people making PHP a stronger typed language and can be a good alternative to scalar type hinting. It provides different typehandling classes as such as integer, float, bool, enum and string

1032.1k](/packages/ducks-project-spl-types)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
