PHPackages                             philiprehberger/php-enum-utils - 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. philiprehberger/php-enum-utils

ActiveLibrary

philiprehberger/php-enum-utils
==============================

Utility trait and helpers for PHP 8.1+ native enums

v1.0.3(1mo ago)11[1 PRs](https://github.com/philiprehberger/php-enum-utils/pulls)MITPHPPHP ^8.2CI passing

Since Mar 15Pushed 1mo agoCompare

[ Source](https://github.com/philiprehberger/php-enum-utils)[ Packagist](https://packagist.org/packages/philiprehberger/php-enum-utils)[ Docs](https://github.com/philiprehberger/php-enum-utils)[ RSS](/packages/philiprehberger-php-enum-utils/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (5)Used By (0)

PHP Enum Utils
==============

[](#php-enum-utils)

[![Tests](https://github.com/philiprehberger/php-enum-utils/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/php-enum-utils/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/6d21851ffc86454b47225caaef3de473aef1ef7dd70435930f2093411a6e662c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f7068702d656e756d2d7574696c732e737667)](https://packagist.org/packages/philiprehberger/php-enum-utils)[![License](https://camo.githubusercontent.com/84662ca45db4c05f6b1865a6b1bf712d95e80c00542fe1479bb8bf129de04577/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068696c69707265686265726765722f7068702d656e756d2d7574696c73)](LICENSE)

Utility trait and helpers for PHP 8.1+ native enums.

---

Requirements
------------

[](#requirements)

DependencyVersionPHP^8.2---

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

[](#installation)

```
composer require philiprehberger/php-enum-utils
```

---

Usage
-----

[](#usage)

### Adding the trait to your enum

[](#adding-the-trait-to-your-enum)

```
use PhilipRehberger\EnumUtils\EnumUtils;
use PhilipRehberger\EnumUtils\Attributes\Label;
use PhilipRehberger\EnumUtils\Attributes\Description;

enum Status: string
{
    use EnumUtils;

    #[Label('Pending Review')]
    #[Description('The item is waiting for review')]
    case Pending = 'pending';

    #[Label('In Progress')]
    case InProgress = 'in_progress';

    case Completed = 'completed';
}
```

### Lookup by name

[](#lookup-by-name)

```
$case = Status::fromName('pending');      // Status::Pending (case-insensitive)
$case = Status::tryFromName('unknown');   // null
```

### Listing cases

[](#listing-cases)

```
Status::names();   // ['Pending', 'InProgress', 'Completed']
Status::values();  // ['pending', 'in_progress', 'completed']
Status::count();   // 3
```

### Arrays for forms and selects

[](#arrays-for-forms-and-selects)

```
Status::toSelectArray();
// ['pending' => 'Pending Review', 'in_progress' => 'In Progress', 'completed' => 'Completed']

Status::toArray();
// ['Pending' => 'pending', 'InProgress' => 'in_progress', 'Completed' => 'completed']
```

### Random case and comparison

[](#random-case-and-comparison)

```
$case = Status::random();                        // A random Status case
Status::Pending->equals(Status::Pending);        // true
Status::Pending->equals(Status::Completed);      // false
```

### Reading attributes with EnumMeta

[](#reading-attributes-with-enummeta)

```
use PhilipRehberger\EnumUtils\EnumMeta;

EnumMeta::label(Status::Pending);         // 'Pending Review'
EnumMeta::label(Status::Completed);       // 'Completed' (fallback: humanized name)
EnumMeta::description(Status::Pending);   // 'The item is waiting for review'
EnumMeta::description(Status::Completed); // null
EnumMeta::labels(Status::class);          // ['pending' => 'Pending Review', ...]
```

---

API
---

[](#api)

### EnumUtils Trait

[](#enumutils-trait)

MethodDescription`::fromName(string $name): static`Case-insensitive lookup by name; throws `ValueError` on miss`::tryFromName(string $name): ?static`Case-insensitive lookup by name; returns `null` on miss`::names(): array`All case names as a flat array`::values(): array`All case values as a flat array`::random(): static`A random case`::toSelectArray(): array``[value => label]` for form selects`::toArray(): array``[name => value]` for serialization`::count(): int`Total number of cases`->equals(self $other): bool`Strict identity comparison### EnumMeta Helper

[](#enummeta-helper)

MethodDescription`EnumMeta::label(BackedEnum $case): string`Label from attribute or humanized name`EnumMeta::description(BackedEnum $case): ?string`Description from attribute or `null``EnumMeta::labels(string $enumClass): array``[value => label]` for all cases### Attributes

[](#attributes)

AttributeTargetPurpose`#[Label('...')]`Enum caseHuman-readable label`#[Description('...')]`Enum caseLonger description text---

Development
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance89

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

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

4

Last Release

53d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

enumhelpersattributesutilitiesphp-enum

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/philiprehberger-php-enum-utils/health.svg)

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

###  Alternatives

[andreas-glaser/php-helpers

A comprehensive collection of PHP utility functions for array manipulation, string operations, date handling, HTML generation, form building, validation, and more. Modern PHP 8.2+ library with full type safety.

1386.5k2](/packages/andreas-glaser-php-helpers)[event4u/data-helpers

Framework-agnostic PHP library for data mapping, DTOs and utilities. Includes DataMapper, SimpleDto/LiteDto, DataAccessor/Mutator/Filter and helper classes (MathHelper, EnvHelper, etc.). Works with Laravel, Symfony/Doctrine or standalone PHP.

1421.5k](/packages/event4u-data-helpers)[zlikavac32/php-enum

Better PHP enum support

225.6k5](/packages/zlikavac32-php-enum)[cse/helpers-session

The helpers allows you to easily manage session data. START, SET, GET DELETE, HAS method session - all this is available in this library.

102.6k3](/packages/cse-helpers-session)

PHPackages © 2026

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