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

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

zul3s/enum-php
==============

Advanced Php Enum Type

1.2.1(4y ago)729.4k↑539.3%1[1 PRs](https://github.com/Zul3s/enum-php/pulls)MITPHPPHP &gt;=7.1CI failing

Since Jul 25Pushed 4y ago3 watchersCompare

[ Source](https://github.com/Zul3s/enum-php)[ Packagist](https://packagist.org/packages/zul3s/enum-php)[ RSS](/packages/zul3s-enum-php/feed)WikiDiscussions master Synced yesterday

READMEChangelog (5)Dependencies (7)Versions (7)Used By (0)

PHP Enum
========

[](#php-enum)

[![Build Status](https://camo.githubusercontent.com/27a45b1ee39e1d58a75563fbecfe1dd3646a3b6b0606270bfdd5666478057e32/68747470733a2f2f7472617669732d63692e6f72672f5a756c33732f656e756d2d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Zul3s/enum-php)[![Latest Stable Version](https://camo.githubusercontent.com/39ddaa46c68dd448ac4dfab76a3ec2dc27a825c429f57c5a3ea45d4c3a235551/68747470733a2f2f706f7365722e707567782e6f72672f7a756c33732f656e756d2d7068702f762f737461626c65)](https://packagist.org/packages/zul3s/enum-php)[![Total Downloads](https://camo.githubusercontent.com/aee16c43c077c661648c473ac35f8df0d97da7aa73b42904d9ed122addb5f9ab/68747470733a2f2f706f7365722e707567782e6f72672f7a756c33732f656e756d2d7068702f646f776e6c6f616473)](https://packagist.org/packages/zul3s/enum-php)[![License](https://camo.githubusercontent.com/411ff5fdec59bb24c8427d9fc9547483d4b68c098f04903e2bbd30e64280c7a7/68747470733a2f2f706f7365722e707567782e6f72672f7a756c33732f656e756d2d7068702f6c6963656e7365)](https://packagist.org/packages/zul3s/enum-php)[![composer.lock](https://camo.githubusercontent.com/008debd822be210830940013677859b37c8b928fafc3e7526c9c743b475f19f1/68747470733a2f2f706f7365722e707567782e6f72672f7a756c33732f656e756d2d7068702f636f6d706f7365726c6f636b)](https://packagist.org/packages/zul3s/enum-php)

PHP &gt;=7.1 only supported.
It's an abstract class that needs to be extended to use it.

What is an Enumeration?
-----------------------

[](#what-is-an-enumeration)

[Wikipedia](http://wikipedia.org/wiki/Enumerated_type)

> 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. The enumerator names are usually identifiers that behave as constants in the language. A variable that has been declared as having an enumerated type can be assigned any of the enumerators as a value. In other words, an enumerated type has values that are different from each other, and that can be compared and assigned, but which do not have any particular concrete representation in the computer's memory; compilers and interpreters can represent them arbitrarily.

### Some advantages

[](#some-advantages)

When you using an enum instead of class constants, you take advantages of

- Type-hint : e.g. function setEnum(Enum $enum)
- Enrich your enum class with methods : e.g. first, format, ...
- Get all possibilities keys/values

Why this ?
----------

[](#why-this-)

Actually you can find others package offer PHP enum implementation, but this package have some advantage :

- Singleton : this package use singleton pattern
- Fast : Implemented small execution cache
- Right way : No circular referential
- Small : this package not needed an other to use
- Quality : PSR-2 standard

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

[](#installation)

```
composer require zul3s/enum-php

```

Declaration
-----------

[](#declaration)

```
use Zul3s\EnumPhp\Enum;

/**
 * Simpson enum
 *
 * @method static Simpson::HOMER()
 * @method static Simpson::MARGE()
 */
class Simpson extends Enum
{
    /**
    * @description('Description for Homer const')
    */
    const HOMER  = 1;
    const MARGE  = 'marjorie_jacqueline';
}

```

Usage
-----

[](#usage)

```
$marge = Simpson::MARGE();

$homer = Simpson::byKey('HOMER');

$marge = Simpson::byValue('marjorie_jacqueline');

$homer = Simpson::byValue('1', false); // Disable strict type mode

```

#### Type-hint

[](#type-hint)

```
function setMember(Simpson $member)
{
    // ...
}

```

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

[](#documentation)

##### Get

[](#get)

- `$myEnum = MyEnumClass::ENUM_CONST()` Return enum search by const name (method name)
- `$myEnum = MyEnumClass::byValue(mixed $value, [optional] bool $strict)` Return enum search by value
- `$myEnum = MyEnumClass::byKey(string $constName)` Return enum search by const name

##### Use

[](#use)

- `$myEnum->getValue() : mixed` Return value of enum
- `$myEnum->getKey() : string` Return string with const name
- `$myEnum->getDescription() : string` Return description annotation if is set or exception
- `$myEnum->isEqual(Enum $myEnum) : bool` Check if enum is equal to another
- `echo $myEnum : string` \_\_toString() have implemented to return cast of string value

##### Helper

[](#helper)

- `MyEnumClass::getAll() : array` Return array with all MyEnum possibilities
- `MyEnumClass::getValues() : array` Return simple associate array with key is const name and value is const value
- `MyEnumClass::isValidKey(string $testedValue) : bool` Check if tested value is valid const name
- `MyEnumClass::isValidValue($testValue, [optional] bool $strict) : bool` Check if tested value is valid const value

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

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

Total

5

Last Release

1790d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/420bfffe679b88778e9f16889186b43e98ba7fa77bf6a98ed24cc945f69ea172?d=identicon)[Zul3s](/maintainers/Zul3s)

---

Top Contributors

[![Zul3s](https://avatars.githubusercontent.com/u/20360716?v=4)](https://github.com/Zul3s "Zul3s (15 commits)")

---

Tags

enum

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[myclabs/php-enum

PHP Enum implementation

2.7k236.1M692](/packages/myclabs-php-enum)[dasprid/enum

PHP 7.1 enum implementation

382165.7M12](/packages/dasprid-enum)[spatie/enum

PHP Enums

85232.6M76](/packages/spatie-enum)[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

50458.3M110](/packages/marc-mabe-php-enum)[spatie/laravel-enum

Laravel Enum support

3685.8M35](/packages/spatie-laravel-enum)[consistence/consistence

Consistence - consistent approach and additions to PHP's functionality

1841.1M18](/packages/consistence-consistence)

PHPackages © 2026

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