PHPackages                             fuwasegu/php-enum-util - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. fuwasegu/php-enum-util

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

fuwasegu/php-enum-util
======================

The extension library for PHP native enum.

3.0.0(3y ago)119.1k↓100%MITPHPPHP ^8.1

Since Feb 28Pushed 3y ago1 watchersCompare

[ Source](https://github.com/fuwasegu/php-enum-util)[ Packagist](https://packagist.org/packages/fuwasegu/php-enum-util)[ RSS](/packages/fuwasegu-php-enum-util/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

🛠 fuwasegu/php-enum-util
========================

[](#-fuwaseguphp-enum-util)

[![Coverage Status](https://camo.githubusercontent.com/5f88662bedbb2229fe8f25819608ea209198e7b4628c5f1e136347ed4cdd49c1/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f66757761736567752f7068702d656e756d2d7574696c2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/fuwasegu/php-enum-util?branch=master)[![example workflow](https://github.com/fuwasegu/php-enum-util/actions/workflows/ci.yml/badge.svg)](https://github.com/fuwasegu/php-enum-util/actions/workflows/ci.yml/badge.svg)[![MIT License](https://camo.githubusercontent.com/db79b92834d905629b1aea42c9aa493da02060189e2af90840b1be5d6bf6ddf7/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c6174)](LICENSE)[![PHP Version Require](https://camo.githubusercontent.com/53fe0ca3c9d016938853fd93593f6dd79d437f5eaee021195e38471063cb7abc/687474703a2f2f706f7365722e707567782e6f72672f66757761736567752f7068702d656e756d2d7574696c2f726571756972652f706870)](https://packagist.org/packages/fuwasegu/php-enum-util)[![Total Downloads](https://camo.githubusercontent.com/b8c63b07f02c366675b5d393e91114c27417b692024a2977c8b0cdfce4b990bf/687474703a2f2f706f7365722e707567782e6f72672f66757761736567752f7068702d656e756d2d7574696c2f646f776e6c6f616473)](https://packagist.org/packages/fuwasegu/php-enum-util)

The extension library for PHP native enum.

📦 Installation
==============

[](#-installation)

```
composer require fuwasegu/php-enum-util
```

✏️ Usage
========

[](#️-usage)

This library provides traits to make Enum, implemented since PHP8.1, easier to use.

### HasDescription trait

[](#hasdescription-trait)

This trait provides an interface to the `description()` method and an implementation of the `descriptions()` method.

```
enum Status: string
{
    use HasDescription;

    case ACTIVE = 'active';

    case INACTIVE = 'inactive';

    case RETIED = 'retired';

    public function description(): string
    {
        return match ($this) {
            self::ACTIVE => 'State in which the employee is enrolled.',
            self::INACTIVE => 'State in which the employee is on administrative leave.',
            self::RETIED => 'State in which employee is retiring.',
        };
    }
}
```

```
// Getter for Enum description
Status::ACTIVE->description();

// Getter for Enum value and description maps
Status::descriptions();
```

### HasLabel trait

[](#haslabel-trait)

This trait provides an interface to the `label()` method and an implementation of the `labels()` method.

```
enum Capital: int
{
    use HasLabel;

    case TOKYO = 1;

    case BEIJING = 2;

    case WASHINGTON = 3;

    case LONDON = 4;

    public function label(): string
    {
        return match ($this) {
            self::TOKYO => 'Tokyo',
            self::BEIJING => 'Beijing',
            self::WASHINGTON => 'Washington',
            self::LONDON => 'London',
        };
    }
}
```

```
// Getter for Enum label
Status::ACTIVE->label();

// Getter for Enum value and label maps
Status::labels();
```

> 📌 NOTICE:
>
> There is no implementation difference between the HasLabel and HasDescription traits. The difference is the method name.
>
> Choose the former if you want a short label for an enum, and choose the latter if you want a long description.

### HasValues trait

[](#hasvalues-trait)

This trait is the value version of the `cases()` method originally implemented in Enum, and provides auxiliary methods.

```
enum Status: string
{
    use HasValues;

    case ACTIVE = 'active';

    case INACTIVE = 'inactive';

    case RETIED = 'retired';
}
```

```
// Getter for Enum values
Status::values();

// Join Enum values with a string
Status::implodeValues();
```

### HasNames trait

[](#hasnames-trait)

This trait is the name version of the `cases()` method originally implemented in Enum, and provides auxiliary methods.

```
enum Status: string
{
    use HasNames;

    case ACTIVE = 'active';

    case INACTIVE = 'inactive';

    case RETIED = 'retired';
}
```

```
// Getter for Enum names
Status::names();

// Join Enum names with a string
Status::implodeNames();
```

### Comparable trait

[](#comparable-trait)

This trait provides a method for easy comparison of Bakced Enums

```
enum Status: string
{
    use Comparable;

    case ACTIVE = 'active';

    case INACTIVE = 'inactive';

    case RETIED = 'retired';
}
```

```
// Compare Enum peer to peer
$maybeActive = Status::ACTIVE;
Status::ACTIVE->is($maybeActive); // true
Status::INACTIVE->isNot($maybeActive); // false

// Attempts to convert the compared int or string to an Enum with Enum::tryFrom before comparing
// If tryFrom is null, `isFrom()` returns false and `isNotFrom()` returns true.
$value = 'active';
Status::ACTIVE->isFrom($value); // true
Status::INACTIVE->isNotFrom($value); // false
Status::ACTIVE->isFrom('foo'); // false
Status::ACTIVE->isNotFrom('foo') // true
```

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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

Every ~0 days

Total

3

Last Release

1166d ago

Major Versions

1.0.0 → 2.0.02023-02-28

2.0.0 → 3.0.02023-02-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/e9d5d8ea70fe4695c076b8f0ac7143841b72ec88ea73fbb0cadf62992daecadb?d=identicon)[fuwasegu](/maintainers/fuwasegu)

---

Top Contributors

[![fuwasegu](https://avatars.githubusercontent.com/u/52437973?v=4)](https://github.com/fuwasegu "fuwasegu (6 commits)")

---

Tags

phpenumutility

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/fuwasegu-php-enum-util/health.svg)

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

###  Alternatives

[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.4k](/packages/ducks-project-spl-types)

PHPackages © 2026

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