PHPackages                             phpnomad/enum-polyfill - 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. phpnomad/enum-polyfill

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

phpnomad/enum-polyfill
======================

1.0.2(3w ago)06.3k↓32.5%[2 PRs](https://github.com/phpnomad/enum-polyfill/pulls)5MITPHPCI passing

Since Feb 13Pushed 2w ago2 watchersCompare

[ Source](https://github.com/phpnomad/enum-polyfill)[ Packagist](https://packagist.org/packages/phpnomad/enum-polyfill)[ Docs](https://github.com/phpnomad/core)[ RSS](/packages/phpnomad-enum-polyfill/feed)WikiDiscussions main Synced yesterday

READMEChangelog (3)Dependencies (4)Versions (9)Used By (5)

phpnomad/enum-polyfill
======================

[](#phpnomadenum-polyfill)

[![Latest Version](https://camo.githubusercontent.com/b59fae4b58ee02d3826e9ba134cbd2d116265b626b5a4748bbead4a52c100c75/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068706e6f6d61642f656e756d2d706f6c7966696c6c2e737667)](https://packagist.org/packages/phpnomad/enum-polyfill)[![Total Downloads](https://camo.githubusercontent.com/dad35fb26a0233d4e7e638f88c88677a0d3bff38c79c634508bfa863c84d2d98/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068706e6f6d61642f656e756d2d706f6c7966696c6c2e737667)](https://packagist.org/packages/phpnomad/enum-polyfill)[![PHP Version](https://camo.githubusercontent.com/4f1eaff89472883cc37088bb3a6f5e5e53ef102c30b99fe4dd720a08c51b4382/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7068706e6f6d61642f656e756d2d706f6c7966696c6c2e737667)](https://packagist.org/packages/phpnomad/enum-polyfill)[![License](https://camo.githubusercontent.com/8d66db6d5e5bfe5c526ecd84c4a6de754ee4f59573154cebdd2d17aa50897061/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068706e6f6d61642f656e756d2d706f6c7966696c6c2e737667)](https://packagist.org/packages/phpnomad/enum-polyfill)

`phpnomad/enum-polyfill` provides a single `Enum` trait that gives any class with constants the method surface of a PHP 8.1 native enum: `cases()`, `from()`, `tryFrom()`, and `isValid()`. It exists so projects targeting PHP 7.4 or 8.0 can use the same enum patterns that ship natively in 8.1+, with a clear path to swap in real enums later.

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

[](#installation)

```
composer require phpnomad/enum-polyfill
```

Quick Start
-----------

[](#quick-start)

```
use PHPNomad\Enum\Traits\Enum;

class Status
{
    use Enum;

    public const Active = 'active';
    public const Pending = 'pending';
    public const Inactive = 'inactive';
}

Status::cases();              // ['active', 'pending', 'inactive']
Status::isValid('active');    // true
Status::tryFrom('banned');    // null
Status::from('active');       // 'active'
```

Overview
--------

[](#overview)

- `cases()` and its alias `getValues()` return every constant value on the class as an array.
- `isValid($value)` runs a strict comparison against the constant values.
- `from($value)` returns the value if valid or throws `UnexpectedValueException`.
- `tryFrom($value)` returns the value if valid or `null`.
- Reflection runs once per class. Values are cached on a singleton via `phpnomad/singleton`.

One thing to know before you migrate: the trait returns the raw constant value (a string, an int, whatever the constant is), not a typed enum instance. When you later move a class to a native PHP 8.1 enum, call sites that were holding `'active'` will need to hold `Status::Active` instead.

Documentation
-------------

[](#documentation)

Full docs at [phpnomad.com](https://phpnomad.com).

License
-------

[](#license)

MIT. See [LICENSE.txt](LICENSE.txt).

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance96

Actively maintained with recent releases

Popularity24

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 78.6% 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 ~270 days

Total

3

Last Release

21d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e6206223bd6f2a57b8ac80605b1b5c3521faaec18ad3f20f25fb728a9a13784?d=identicon)[tstandiford](/maintainers/tstandiford)

---

Top Contributors

[![alexstandiford](https://avatars.githubusercontent.com/u/8210827?v=4)](https://github.com/alexstandiford "alexstandiford (11 commits)")[![malayladu](https://avatars.githubusercontent.com/u/708174?v=4)](https://github.com/malayladu "malayladu (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

enumframeworkphpphpnomadplatform-agnosticpolyfill

### Embed Badge

![Health badge](/badges/phpnomad-enum-polyfill/health.svg)

```
[![Health](https://phpackages.com/badges/phpnomad-enum-polyfill/health.svg)](https://phpackages.com/packages/phpnomad-enum-polyfill)
```

###  Alternatives

[yajra/laravel-disqus

A simple Disqus platform integration with Laravel.

8457.5k](/packages/yajra-laravel-disqus)

PHPackages © 2026

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