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

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

desmart/php-enum
================

Strongly-typed enum objects for PHP

1.0.0(5y ago)04641MITPHPPHP ^7.4|^8.0

Since Mar 4Pushed 5y ago5 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (2)Used By (1)

PHP Enum 📚
==========

[](#php-enum-)

[![Latest version](https://camo.githubusercontent.com/efea8532908fc7da472e12e2038bd58b2f8213c652159927f12ce664bde07f57/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6465736d6172742f7068702d656e756d2e7376673f7374796c653d666c6174)](https://github.com/DeSmart/php-enum)[![Tests](https://github.com/desmart/php-enum/workflows/Run%20Tests/badge.svg)](https://github.com/desmart/php-enum/workflows/Run%20Tests/badge.svg)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](https://github.com/DeSmart/php-enum/blob/master/LICENSE)

Package provides a strongly typed enums for PHP.

> `Enumeration` class name is used on purpose, to avoid potential issues. There will be native enums in PHP 8.1 🎉

> There are other great packages implementing enums for PHP. Consider checking them out!

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

[](#installation)

To install the package via Composer, simply run the following command:

```
composer require desmart/php-enum

```

Usage
-----

[](#usage)

Example enum definition:

```
/**
 * @method static Character good()
 * @method static Character evil()
 * @method static Character sometimesGoodSometimesEvil()
 */
class Character extends Enumeration
{
    const GOOD = 'good';
    const EVIL = 'evil';
    const SOMETIMES_GOOD_SOMETIMES_EVIL = 'sometimes_good_or_evil';
}
```

#### Create an enum object

[](#create-an-enum-object)

```
$enum = Character::good(); // or Character::fromName('good')
```

In general, named constructor method name should be a constant name in camelCase.

> Few exceptions to this rule are allowed. See [test file](https://github.com/DeSmart/php-enum/blob/master/tests/EnumerationTest.php).

#### Create an enum object based on available constants' values

[](#create-an-enum-object-based-on-available-constants-values)

```
$enum = Character::fromValue('sometimes_good_or_evil');
```

This approach is very convenient when enum objects are created from eg. database.

#### Comparing enums

[](#comparing-enums)

```
Character::good()->equals(Character::fromName('good')); // true
Character::good()->equals(Character::evil());           // false
Character::good()->equals(OtherEnum::someValue());      // false
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity57

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

Unknown

Total

1

Last Release

1901d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a3c56cab812fc073277f1e127a12e0c6066565dc57bd3045484fcca1901021b?d=identicon)[gollum](/maintainers/gollum)

---

Top Contributors

[![golonix](https://avatars.githubusercontent.com/u/9950778?v=4)](https://github.com/golonix "golonix (9 commits)")

---

Tags

enumenumerationenumsphpphpenumdesmart

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[kongulov/interact-with-enum

Trait for convenient use of ENUM in PHP

3052.3k2](/packages/kongulov-interact-with-enum)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)[vjik/php-enum

PHP Enum Implementation

209.9k](/packages/vjik-php-enum)[ducks-project/spl-types

Polyfill Module for SplType PHP extension. This extension aims at helping people making PHP a stronger typed language and can be a good alternative to scalar type hinting. It provides different typehandling classes as such as integer, float, bool, enum and string

1032.4k](/packages/ducks-project-spl-types)

PHPackages © 2026

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