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

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

ngmy/enum
=========

The enumeration type for PHP

0.7.0(5y ago)0570[1 PRs](https://github.com/ngmy/php-enum/pulls)MITPHPPHP ^7.3|^8.0

Since Feb 22Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ngmy/php-enum)[ Packagist](https://packagist.org/packages/ngmy/enum)[ Fund](https://flattr.com/@ngmy)[ GitHub Sponsors](https://github.com/ngmy)[ RSS](/packages/ngmy-enum/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (1)Versions (9)Used By (0)

PHP Enum
========

[](#php-enum)

[![Latest Stable Version](https://camo.githubusercontent.com/402f8c95c5abfff8d6de551804cd0861d2c2b445d0b577642a2c7a2f728b5c20/68747470733a2f2f706f7365722e707567782e6f72672f6e676d792f656e756d2f76)](//packagist.org/packages/ngmy/enum)[![Total Downloads](https://camo.githubusercontent.com/19d7f2781f29fb903a2a6ff0a6748e304e95f774ecb2f5694ee75056d179b43e/68747470733a2f2f706f7365722e707567782e6f72672f6e676d792f656e756d2f646f776e6c6f616473)](//packagist.org/packages/ngmy/enum)[![Latest Unstable Version](https://camo.githubusercontent.com/a9e87aa5e8ace45732955e38cad288b2ce5dcdc963771f3cd7f3762052a53bae/68747470733a2f2f706f7365722e707567782e6f72672f6e676d792f656e756d2f762f756e737461626c65)](//packagist.org/packages/ngmy/enum)[![License](https://camo.githubusercontent.com/37daaedf3696f457d970a318876ec109152c3b76165d1004ada6fd5a4ee9b7ca/68747470733a2f2f706f7365722e707567782e6f72672f6e676d792f656e756d2f6c6963656e7365)](//packagist.org/packages/ngmy/enum)[![composer.lock](https://camo.githubusercontent.com/eb3a738423a949765d2775f87a65c2ce09c38fa5b3e996e1925bbc8bdf27bbef/68747470733a2f2f706f7365722e707567782e6f72672f6e676d792f656e756d2f636f6d706f7365726c6f636b)](//packagist.org/packages/ngmy/enum)[![PHP CI](https://github.com/ngmy/php-typed-array/actions/workflows/php.yml/badge.svg)](https://github.com/ngmy/php-typed-array/actions/workflows/php.yml)[![Coverage Status](https://camo.githubusercontent.com/305ca0627ee8ffa5342e6d0d6150cdc4505f1f356d9797125d5430c12d4ff193/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6e676d792f7068702d656e756d2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/ngmy/php-enum?branch=master)[![PHPStan](https://camo.githubusercontent.com/441b5874ce4df0a2defc892979c96c46889b69cb32119d04f0b48626349f8bc9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/phpstan/phpstan)[![Psalm Coverage](https://camo.githubusercontent.com/b291d2292f0a792eaf1586895cb0784336f0ce6737a5ea24b9ba3111779b5374/68747470733a2f2f73686570686572642e6465762f6769746875622f6e676d792f7068702d74797065642d61727261792f636f7665726167652e7376673f)](https://shepherd.dev/github/ngmy/php-typed-array)[![Psalm Level](https://camo.githubusercontent.com/ae7dc350f954ae6008c8fdf890c0aaa2251008c0224a9df7c3cdcf47e2fc13b7/68747470733a2f2f73686570686572642e6465762f6769746875622f6e676d792f7068702d74797065642d61727261792f6c6576656c2e7376673f)](https://shepherd.dev/github/ngmy/php-typed-array)

PHP Enum is the enumeration type for PHP.

- Interface like the enum type of Java
- Also provides the enum map and set like Java
- Supports the static analysis like PHPStan and Psalm. Please see [examples](docs/examples)

```
/**
 * @method static self FOO()
 * @method static self BAR()
 * @method static self BAZ()
 */
class Enum1 extends Ngmy\Enum\Enum
{
    /** @enum */
    private static $FOO;
    /** @enum */
    private static $BAR;
    /** @enum */
    private static $BAZ;
}

// Returns the enum constant of the specified name
$foo = Enum1::valueOf('FOO');
$bar = Enum1::valueOf('BAR');
$baz = Enum1::valueOf('BAZ');
// You can also use magic factory methods
$foo = Enum1::FOO();
$bar = Enum1::BAR();
$baz = Enum1::BAZ();

// Returns the name of this enum constant, exactly as declared in its enum declaration
echo $foo->name() . PHP_EOL; // FOO
echo $bar->name() . PHP_EOL; // BAR
echo $baz->name() . PHP_EOL; // BAZ

// Returns the name of this enum constant, as contained in the declaration
echo $foo . PHP_EOL; // FOO
echo $bar . PHP_EOL; // BAR
echo $baz . PHP_EOL; // BAZ

// Returns the ordinal of this enum constant
echo $foo->ordinal() . PHP_EOL; // 0
echo $bar->ordinal() . PHP_EOL; // 1
echo $baz->ordinal() . PHP_EOL; // 2

// Returns true if the specified object is equal to this enum constant
echo var_export($foo->equals($foo), true) . PHP_EOL;                  // true
echo var_export($foo->equals(Enum1::valueOf('FOO')), true) . PHP_EOL; // true
echo var_export($foo->equals($bar), true) . PHP_EOL;                  // false

// You can also have the enum constant with a value

/**
 * @method static self FOO()
 * @method static self BAR()
 * @method static self BAZ()
 */
class Enum2 extends Ngmy\Enum\Enum
{
    /** @enum */
    private static $FOO = 1;
    /** @enum */
    private static $BAR = 2;
    /** @enum */
    private static $BAZ = 3;

    public function getValue(): int
    {
        return self::${$this->name()};
    }
}

echo Enum2::valueOf('FOO')->getValue() . PHP_EOL; // 1
echo Enum2::valueOf('BAR')->getValue() . PHP_EOL; // 2
echo Enum2::valueOf('BAZ')->getValue() . PHP_EOL; // 3
```

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

[](#requirements)

PHP Enum has the following requirements:

- PHP &gt;= 7.3

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

[](#installation)

Execute the Composer `require` command:

```
composer require ngmy/enum
```

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

[](#documentation)

Please see the [API documentation](https://ngmy.github.io/php-enum/api/).

License
-------

[](#license)

PHP Enum is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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 ~6 days

Total

7

Last Release

1871d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/864041?v=4)[Yuta Nagamiya](/maintainers/ngmy)[@ngmy](https://github.com/ngmy)

---

Top Contributors

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

---

Tags

arrayenumenum-mapenum-setenumerationlibrarymapphpphp-librarysettypetypeenummapenumerationsetenum-setenum-map

### Embed Badge

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

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

###  Alternatives

[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

49444.8M97](/packages/marc-mabe-php-enum)[phpcollection/phpcollection

General-Purpose Collection Library for PHP

1.0k64.0M34](/packages/phpcollection-phpcollection)[dasprid/enum

PHP 7.1 enum implementation

379146.0M11](/packages/dasprid-enum)[consistence/consistence

Consistence - consistent approach and additions to PHP's functionality

1831.1M18](/packages/consistence-consistence)[cerbero/enum

Zero-dependencies package to supercharge enum functionalities.

359207.5k2](/packages/cerbero-enum)[garoevans/php-enum

Convenient way to always have an Enum object available and utilise Spl Types if available.

19158.8k5](/packages/garoevans-php-enum)

PHPackages © 2026

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