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

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

php-compatible/enum
===================

PHP 8 enums compatible for PHP 7

v1.1.0(4mo ago)03MITPHPPHP &gt;=7.2CI passing

Since Dec 30Pushed 4mo agoCompare

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

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

Enum
====

[](#enum)

[![CI](https://github.com/php-compatible/enum/actions/workflows/ci.yml/badge.svg)](https://github.com/php-compatible/enum/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/7e8411b022ffcfe4737714825acd072629ed6a12a7fd5c51d8d6e120a3eea21e/68747470733a2f2f636f6465636f762e696f2f67682f7068702d636f6d70617469626c652f656e756d2f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/php-compatible/enum)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](https://github.com/php-compatible/enum/blob/main/LICENSE)

[![PHP 7.2](https://camo.githubusercontent.com/9009d4cd3bbc8ab0e6e2ecb7a8f515d7acdaf5bed78b54fbc4f3302aca185fdb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e322d383839324246)](https://github.com/php-compatible/enum/actions/workflows/ci.yml)[![PHP 7.3](https://camo.githubusercontent.com/808ba600bbb9250ea354ab20f74f4cba5bb53a63e69a735c666d7e9d953b77be/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e332d383839324246)](https://github.com/php-compatible/enum/actions/workflows/ci.yml)[![PHP 7.4](https://camo.githubusercontent.com/6349d14f5bbb5fd01c8b1106f8cb7a336d8d6cb666b7a5dcf53b2f393e872555/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e342d383839324246)](https://github.com/php-compatible/enum/actions/workflows/ci.yml)[![PHP 8.0](https://camo.githubusercontent.com/f8d5653e4281c2efc94e0870ed308de4b80722228f2d8093e2a9a0de2e5f55a4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e302d383839324246)](https://github.com/php-compatible/enum/actions/workflows/ci.yml)[![PHP 8.1](https://camo.githubusercontent.com/d49f87c0064ba3e52bafae43fb293c6a3fec111158fcfbeea0e230c4925a4862/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312d383839324246)](https://github.com/php-compatible/enum/actions/workflows/ci.yml)[![PHP 8.2](https://camo.githubusercontent.com/ebae3d97f0073d1bea07aabd07eb8bcd15d0b0da5ed262e0fcdf9ac1b097f757/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322d383839324246)](https://github.com/php-compatible/enum/actions/workflows/ci.yml)[![PHP 8.3](https://camo.githubusercontent.com/e133742f32b8cc0a4de190d0b780dbfff6796a051c0721835577b3b6a914a10e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332d383839324246)](https://github.com/php-compatible/enum/actions/workflows/ci.yml)[![PHP 8.4](https://camo.githubusercontent.com/1bf14f8d457f351d4b4d220de872952b3b344296479d588aaa3aa79b8fde41d2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e342d383839324246)](https://github.com/php-compatible/enum/actions/workflows/ci.yml)[![PHP 8.5](https://camo.githubusercontent.com/ce65ce4d8264a7d2bb55e05a2ced7dded2ea3ccad77c1ce884305ee27776cccd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e352d383839324246)](https://github.com/php-compatible/enum/actions/workflows/ci.yml)

**PHP 8-style enums for PHP 7.2+** - Write enums today, upgrade to native enums tomorrow.

This library provides a PHP 8-compatible enum API that works on PHP 7.2 and above. When you're ready to upgrade to PHP 8.1+, use the included migration tool to automatically convert your enums to native PHP syntax.

Why Use This Package?
---------------------

[](#why-use-this-package)

- **Future-proof**: API mirrors PHP 8 enums (`from()`, `tryFrom()`, `cases()`)
- **Zero-friction migration**: Automated upgrade tool converts to native PHP 8 enums
- **IDE-friendly**: CLI tool auto-generates PHPDoc annotations for full autocompletion
- **Flexible**: Case-insensitive access, auto-increment values, string or int backing
- **Human-readable labels**: Built-in conversion from `camelCase` to `Camel Case`
- **Type-safe**: Strict type comparison for value lookups (matches PHP 8 behavior)
- **Well-tested**: 100% code coverage across PHP 7.2 - 8.5

CLI Tools Included
------------------

[](#cli-tools-included)

CommandDescription`vendor/bin/php-compatible-enum-auto-doc`Auto-generate `@method` PHPDoc annotations for IDE support`vendor/bin/php-compatible-enum-upgrade-to-php8`Migrate enums to native PHP 8.1+ syntaxInstallation
------------

[](#installation)

```
composer require php-compatible/enum
```

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

[](#documentation)

Full documentation available at [phpcompatible.dev/docs/category/enum](https://phpcompatible.dev/docs/category/enum)

Usage
-----

[](#usage)

### Basic Enum (Auto-increment)

[](#basic-enum-auto-increment)

Define enum cases as protected properties. Uninitialized properties auto-increment from 0:

```
