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

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

ggergo/enum
===========

Enum implementation for PHP

v1.0.1(5y ago)02MITPHPPHP ^7.1

Since Sep 9Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ggergo/enum)[ Packagist](https://packagist.org/packages/ggergo/enum)[ RSS](/packages/ggergo-enum/feed)WikiDiscussions master Synced 6d ago

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

Enum
====

[](#enum)

Goals
-----

[](#goals)

To handle Enum arguments

```
function(MyEnumInterface $myEnum)
{
}

```

To always work with instances rather than strings

```
$myEnum = MyEnum::MY_CONSTANT();

// won't work if you use private constants
$myEnum = MyEnum::MY_CONSTANT;

```

Comparison

```
$myEnum.isEqual(MyEnum::MY_CONSTANT());

```

To avoid the reimplementation of functions in every Enum implementation

```
...
class MyEnum extends Enum implements ClassMapEnumInterface, LabelMapEnumInterface
{
    use ClassMapEnumTrait;
    use LabelMapEnumTrait;
...

```

To make DEFAULT not special

```
// Start constant names with underscore when defining not unique values, like a default value.
private const _DEFAULT = self::APPLE;

```

To access the native value in case of transformation

```
$myEnum->getValue();

```

To create an instance from a native value in case of a reverse transformation

```
$myEnum = MyEnum::createByValue($myValue);

```

To use a cache per Enum abstraction to save memory and to speed up accessing constants and serving Enum instances.

Example implementation
----------------------

[](#example-implementation)

Take a look at src/Mock/SimpleFruitEnum.php for a simple implementation.

Take a look at src/Mock/FruitEnum.php to see how to extend the functionality.

Installing
----------

[](#installing)

Require with composer, ie.:

```
{
    "require": {
        "ggergo/enum": "*"
    }
}

```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

2

Last Release

2076d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/22af1787d372106e16f30abe8340a859872db33ae4a34cd62b0565bb1306a1a7?d=identicon)[ggergo](/maintainers/ggergo)

---

Top Contributors

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

---

Tags

enum

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[myclabs/php-enum

PHP Enum implementation

2.7k227.9M637](/packages/myclabs-php-enum)[dasprid/enum

PHP 7.1 enum implementation

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

PHP Enums

84429.1M68](/packages/spatie-enum)[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

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

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[consistence/consistence

Consistence - consistent approach and additions to PHP's functionality

1831.1M18](/packages/consistence-consistence)

PHPackages © 2026

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