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

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

klamius/php-enum
================

A PHP library providing a way to work with enumeration

1.0.1(7y ago)18MITPHPPHP &gt;=5.3

Since Aug 23Pushed 7y agoCompare

[ Source](https://github.com/Klamius/php-enum)[ Packagist](https://packagist.org/packages/klamius/php-enum)[ Docs](http://github.com/klamius/php-enum)[ RSS](/packages/klamius-php-enum/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

PHP Enum inspired by SplEnum
============================

[](#php-enum-inspired-by-splenum)

[![Build Status](https://camo.githubusercontent.com/0c752d6534ef0d1673b751ec8d2466ae30b2f4f3e3ce00adae7c858bdc857a7d/68747470733a2f2f7472617669732d63692e6f72672f4b6c616d6975732f7068702d656e756d2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/Klamius/php-enum)[![Code Coverage](https://camo.githubusercontent.com/c56e5d89219e6744ee678c4d3d2ce276bd6db93f4cd5931d22cb5c10d1d1b195/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4b6c616d6975732f7068702d656e756d2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Klamius/php-enum/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/5fee76ba3c52553b12ffffc664b8312b0c6cea2f80b0bf957d32e554d90cb34a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4b6c616d6975732f7068702d656e756d2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Klamius/php-enum/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/933e2e5009bf17f27c02fc945158dad4296ab2a47a7f233707146db5a046d637/68747470733a2f2f706f7365722e707567782e6f72672f4b6c616d6975732f7068702d656e756d2f646f776e6c6f6164732e706e67)](https://packagist.org/packages/Klamius/php-enum)[![Latest Stable Version](https://camo.githubusercontent.com/373b0b2341c06bf74831ec868d93812fed98557e791049020e9fd2b673456b00/68747470733a2f2f706f7365722e707567782e6f72672f4b6c616d6975732f7068702d656e756d2f762f737461626c652e706e67)](https://packagist.org/packages/Klamius/php-enum)

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

[](#installation)

by using [composer](https://getcomposer.org/)

```
composer require klamius/php-enum

```

Philosophie
-----------

[](#philosophie)

This library give an easier way to emulate and create enumeration objects natively in PHP and be replacement to `SplEnum` which is not integrated directly to PHP.

In our daily usage we deal with many enums (all domain entity states, months, genders, etc. ) and we get into dilemma, should it be Class member, constants or Interface constants and so on. and then we treat it as a scalar value which most of time can't be validated or type hinted.

So using an enum instead of constants provides the following advantages:

- type hint: `function setState(OrderStateEnum $state) {`

### Declaration

[](#declaration)

```
use Klamius\Enum\Enum;

/**
 * GenderEnum enum
 */
class Gender extends Enum
{
    const MALE = 'male';
    const FEMALE = 'female';
}
```

### Usage

[](#usage)

```
class User
{
    /**
     * @var Gender
     */
    private $gender;

    function setGender(Gender $gender)
    {
        $this->gender = $gender;
    }
}

$gender = new Gender(Gender::MALE);
$user->setGender($gender);

//or
echo $gender;
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

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

2821d ago

### Community

Maintainers

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

---

Tags

enumenumerationphp-enumOOP

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

49444.8M97](/packages/marc-mabe-php-enum)[cerbero/enum

Zero-dependencies package to supercharge enum functionalities.

359207.5k2](/packages/cerbero-enum)[cerbero/laravel-enum

Laravel package to supercharge enum functionalities.

18989.6k](/packages/cerbero-laravel-enum)[emreyarligan/enum-concern

A PHP package for effortless Enumeration handling with Laravel Collections 📦 ✨

21156.3k1](/packages/emreyarligan-enum-concern)[rexlabs/enum

Enumeration (enum) implementation for PHP

48482.2k2](/packages/rexlabs-enum)[thunderer/platenum

PHP enum library

36145.7k](/packages/thunderer-platenum)

PHPackages © 2026

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