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

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

miladrahimi/php-enum
====================

A PHP Abstract Enum Class

v1.3(4y ago)1113.0k↓45.8%2MITPHPPHP &gt;=7.1|^8.0CI failing

Since Dec 30Pushed 3y ago1 watchersCompare

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

READMEChangelog (4)Dependencies (1)Versions (6)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/5bdc3075545fed5517da176a847b92e88624b61130b8e3be82668ab180effa80/68747470733a2f2f706f7365722e707567782e6f72672f6d696c6164726168696d692f7068702d656e756d2f762f737461626c65)](https://packagist.org/packages/miladrahimi/php-enum)[![Total Downloads](https://camo.githubusercontent.com/92d7a84218e628a7f66548098c9b357b8ef3ff8f1090c1377ce9bc19e6b87d72/68747470733a2f2f706f7365722e707567782e6f72672f6d696c6164726168696d692f7068702d656e756d2f646f776e6c6f616473)](https://packagist.org/packages/miladrahimi/php-enum)[![Build Status](https://camo.githubusercontent.com/bd448540f5e98ed9a242b62a0206226a081e00794c97f4621c11ddc82e2141f8/68747470733a2f2f7472617669732d63692e6f72672f6d696c6164726168696d692f7068702d656e756d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/miladrahimi/php-enum)[![Coverage Status](https://camo.githubusercontent.com/753b7fe19baf21a9c9b0763a7f1e3519e2e44045e7ff8985c9796620cc8ed3cc/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d696c6164726168696d692f7068702d656e756d2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/miladrahimi/php-enum?branch=master)[![License](https://camo.githubusercontent.com/076e69a8f16763180242bb3a4594f8cadb16535947f4ffe060b347ed27f15f0f/68747470733a2f2f706f7365722e707567782e6f72672f6d696c6164726168696d692f7068702d656e756d2f6c6963656e7365)](https://packagist.org/packages/miladrahimi/php-enum)

PHP-Enum
========

[](#php-enum)

To make your Enums feel alive, just make them extend `Enum` abstract class!

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

[](#installation)

Install [Composer](https://getcomposer.org) and run following command in your project's root directory:

```
composer require miladrahimi/php-enum "1.*"

```

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

[](#documentation)

Consider this enum class:

```
namespace MiladRahimi\Enum\Enum;

class SampleEnum extends Enum
{
    const UNO = 1;
    const ONE = 1;
    const TWO = 2;
    const STR = "sth";
}
```

Now you are able to use this methods:

```
SampleEnum::all(); // ['UNO' => 1, 'ONE' => 1, 'TWO' => 2, 'STR' => 'sth']

SampleEnum::keys(); // ['UNO', 'ONE', 'TWO', 'STR'];

SampleEnum::values(); // [1, 1, 2, 'sth']

SampleEnum::hasKey('ONE'); // true

SampleEnum::hasKey('xXx'); // false

SampleEnum::hasValue(2); // true

SampleEnum::hasValue('xXx'); // false

SampleEnum::valueOf('ONE'); // 1

SampleEnum::keysOf(1); // ['UNO', 'ONE']

SampleEnum::keyOf(1); // 'UNO'

SampleEnum::randomKey(); // One of 'UNO', 'ONE', 'TWO', 'STR'

SampleEnum::randomKeyExceptKeys(['ONE', 'TWO']); // One of 'UNO', 'STR'

SampleEnum::randomKeyExceptValues([SampleEnum::STR, SampleEnum::TWO]); // One of 'ONE', 'UNO'

SampleEnum::randomValue(); // One of 1, 2, 'sth'

SampleEnum::randomValueExceptValues([SampleEnum::STR, SampleEnum::TWO]); // One of SampleEnum::ONE, SampleEnum::UNO

SampleEnum::randomValueExceptKeys(['STR', 'TWO']); // One of SampleEnum::ONE, SampleEnum::UNO
```

License
-------

[](#license)

PHP-Enum is initially created by [Milad Rahimi](https://miladrahimi.com)and released under the [MIT License](http://opensource.org/licenses/mit-license.php).

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity66

Established project with proven stability

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

Total

5

Last Release

1749d ago

PHP version history (2 changes)v1.0PHP &gt;=7.1

v1.2PHP &gt;=7.1|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/921274b8bb29236d8f94f6c83100a5f751f6394c4c49741e1b92bfbccac0911b?d=identicon)[miladrahimi](/maintainers/miladrahimi)

---

Top Contributors

[![miladrahimi](https://avatars.githubusercontent.com/u/6689295?v=4)](https://github.com/miladrahimi "miladrahimi (16 commits)")

---

Tags

enumpackagephpenumAbstract EnumEnumerated type

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[myclabs/php-enum

PHP Enum implementation

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

PHP 7.1 enum implementation

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

PHP Enums

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

Simple and fast implementation of enumerations with native PHP

49644.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)
