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

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

wirus15/enum
============

A simple PHP library for creating enum objects.

0.5.1(8y ago)17.8k1MITPHPPHP &gt;=7

Since Feb 6Pushed 8y ago1 watchersCompare

[ Source](https://github.com/wirus15/enum)[ Packagist](https://packagist.org/packages/wirus15/enum)[ Docs](https://github.com/wirus15/enum)[ RSS](/packages/wirus15-enum/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (2)Versions (5)Used By (0)

Enum
====

[](#enum)

A simple PHP library for creating Enum objects.

Examples
--------

[](#examples)

Defining a new Enum class

```
use Enum\Enum;

// defining our Enum class
final class Example extends Enum
{
    const FOO = 1;
    const BAR = 2;
    const YOLO = 3;
}
```

Basic usage

```
$foo = Example::get(Example::FOO);
$bar = Example::get('bar');
$yolo = Example::YOLO();

function test(Example $enum)
{
    if ($enum->is(Example::FOO)) {
        echo 'foo';
    } else if ($enum->is(Example::BAR)) {
        echo 'bar';
    } else {
        echo $enum;
    }
}

test($foo);   // foo
test($bar);   // bar
test($yolo);  // Yolo
```

Getting Enum instances, listing keys and values

```
Example::get(Example::FOO);               // instance of Example
Example::FOO();                           // shortcut
Example::all();                           // array of Example instances

// keys and values
Example::keys();                          // array of keys ['FOO', 'BAR', 'YOLO']
Example::values();                        // array of values [1, 2, 3]

// checking if value exists
Example::has(3);                          // true
Example::has(4);                          // false
```

Getting single Enum properties

```
$foo = Example::FOO();
$foo->key();                              // 'FOO'
$foo->value();                            // 1
```

Comparing Enums

```
$foo = Example::FOO();
$foo->is(1);                              // true
$foo->is(Example::FOO);                   // true
$foo->is($foo);                           // true

// comparing with strict option (type comparison)
$foo->is($foo, true);                     // true
$foo->is(1, true);                        // false

// searching in array
$foo->in([1,2,3]);                        // true
$foo->in([2,3]);                          // false
```

You can also make static calls and specify Enum class

```
Enum::get(Example::FOO, Example::class);
Enum::all(Example::class);
Enum::keys(Example::class);
Enum::values(Example::class);
Enum::has(1, Example::class);
```

Development and tests
---------------------

[](#development-and-tests)

To develop this lib we are using [docker](http://docker.io) and [docker-compose](https://docs.docker.com/compose/overview/). After installation of those you should run:

```
bash
docker-compose run enum bash

```

Then on docker console run:

```
composer install
composer test
```

License
-------

[](#license)

This library is released under [MIT license](./LICENSE.md).

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

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

###  Release Activity

Cadence

Every ~241 days

Total

4

Last Release

3074d ago

PHP version history (2 changes)0.1PHP &gt;=5.5

0.5.1PHP &gt;=7

### Community

Maintainers

![](https://www.gravatar.com/avatar/e909261828c5d50e06bb9bd3652b50ed339c961087eaad30a89966fed7fcb20e?d=identicon)[wirus15](/maintainers/wirus15)

---

Top Contributors

[![wirus15](https://avatars.githubusercontent.com/u/3389285?v=4)](https://github.com/wirus15 "wirus15 (53 commits)")[![teklakct](https://avatars.githubusercontent.com/u/1399832?v=4)](https://github.com/teklakct "teklakct (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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