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

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

gpslab/enum
===========

Simple and fast implementation of enumerations

1322[1 issues](https://github.com/gpslab/enum/issues)PHPCI failing

Since Dec 19Pushed 6y ago1 watchersCompare

[ Source](https://github.com/gpslab/enum)[ Packagist](https://packagist.org/packages/gpslab/enum)[ RSS](/packages/gpslab-enum/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/0615bf043d2b94cfa579f28afde66a4ecfee10a1fe36bcee34f1169b296864b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6770736c61622f656e756d2e7376673f6d61784167653d33363030266c6162656c3d737461626c65)](https://packagist.org/packages/gpslab/enum)[![Total Downloads](https://camo.githubusercontent.com/4b7248ad1f383d10a64e08822de53413d744e13401ddca21407f5897a99ab648/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6770736c61622f656e756d2e7376673f6d61784167653d33363030)](https://packagist.org/packages/gpslab/enum)[![Build Status](https://camo.githubusercontent.com/8c49782e289c100a638a2b759dbee9df0822ffc620219edb92202006fd48b2cf/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6770736c61622f656e756d2e7376673f6d61784167653d33363030)](https://travis-ci.org/gpslab/enum)[![Coverage Status](https://camo.githubusercontent.com/43acf7ca09b83fb56d4be42b6d9faa30f81a89e378267428028d85876ec2a2d1/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6770736c61622f656e756d2e7376673f6d61784167653d33363030)](https://coveralls.io/github/gpslab/enum?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ec353eba9aedfc35937c95136b848b15a3182fcbf830c08c59dd4f71bf2837c7/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6770736c61622f656e756d2e7376673f6d61784167653d33363030)](https://scrutinizer-ci.com/g/gpslab/enum/?branch=master)[![SensioLabs Insight](https://camo.githubusercontent.com/5f1ae900a5be03e750aafb53edde38d01514cbc35f05668bc1ff333ed8c7fb17/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f35333566643163322d376230372d343765372d626361612d3730326530383166333165382e7376673f6d61784167653d33363030266c6162656c3d534c496e7369676874)](https://insight.sensiolabs.com/projects/535fd1c2-7b07-47e7-bcaa-702e081f31e8)[![StyleCI](https://camo.githubusercontent.com/f9e9e8f9dc0f6c4c39474bd0513c887a5d843d6cb79821764e5b3810b5942053/68747470733a2f2f7374796c6563692e696f2f7265706f732f39313436363034382f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/91466048)[![License](https://camo.githubusercontent.com/e89653a38bb0c5be05ecf767f8e4b5523a29f4bd0598429e03fe7506d6812523/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6770736c61622f656e756d2e7376673f6d61784167653d33363030)](https://github.com/gpslab/enum)

PHP enum
========

[](#php-enum)

Simple and fast implementation of enumerations

Introduction
------------

[](#introduction)

### Definition

[](#definition)

> In computer programming, an **enumerated type**(also called **enumeration** or **enum**) is a data type consisting of a set of named values called **elements**, members or enumerators of the type. — [Wikipedia](http://en.wikipedia.org/wiki/Enumerated_type)

### SplEnum

[](#splenum)

[SplEnum](http://php.net/manual/en/class.splenum.php) is not integrated to PHP, you have to install it separately:

`$ sudo pecl install SPL_Types`.

In addition, it's not a panacea:

```
class Month extends SplEnum {
    const JANUARY  = 1;
    const FEBRUARY = 2;
}

class Fruit extends SplEnum {
    const APPLE  = 1;
    const ORANGE = 2;
}

// you must create new instance before each use:
$jan   = new Month(Month::JANUARY);
$jan2  = new Month(Month::JANUARY);
$apple = new Fruit(Fruit::APPLE);

var_dump($jan === $jan2);          // false
var_dump($jan === Month::JANUARY); // false
var_dump($jan ==  Fruit::APPLE);   // true
```

### Benchmark

[](#benchmark)

Enum benchmark on PHP 7

```
$ tests/benchmark/enum.php 100000

 ------------------------------- ------------ --------------
  Test                            Memory Avg   Duration All
 ------------------------------- ------------ --------------
  Reflection enum                 1.52 KiB     1820 ms
  Reflection enum (no magic)      1.52 KiB     1718 ms
  Explicit enum                   0.71 KiB     959 ms
  myclabs/php-enum                0.68 KiB     1971 ms
  marc-mabe/php-enum              1.59 KiB     2219 ms
  marc-mabe/php-enum (no magic)   1.59 KiB     1969 ms
  happy-types/enumerable-type     1.81 KiB     2322 ms
 ------------------------------- ------------ --------------

```

Set benchmark on PHP 7

```
$ tests/benchmark/set.php 100000

 -------------------- ------------ --------------
  Test                 Memory Avg   Duration All
 -------------------- ------------ --------------
  Reflection set       1.36 KiB     1238 ms
  marc-mabe/php-enum   1.59 KiB     2861 ms
 -------------------- ------------ --------------

```

### How to get enum with default value?

[](#how-to-get-enum-with-default-value)

```
final class Color extends ReflectionEnum implements EnumDefault
{
    const RED = 1;
    const GREEN = 2;
    const BLUE = 3;

    /**
     * @return Color
     */
    public static function byDefault()
    {
        return self::byValue(self::RED);
    }
}
```

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 99.1% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/9a6415c83577efe7b70d9ae4a3bb12958adc11c16e530ff844ff217b0fd0c54a?d=identicon)[Peter Gribanov](/maintainers/Peter%20Gribanov)

---

Top Contributors

[![peter-gribanov](https://avatars.githubusercontent.com/u/1954436?v=4)](https://github.com/peter-gribanov "peter-gribanov (110 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

enumenumerationphpset

### Embed Badge

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

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

###  Alternatives

[loilo/lowlight

Show syntax-highlighted code of 150+ languages in your terminal

201.6k1](/packages/loilo-lowlight)

PHPackages © 2026

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