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

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

konekt/enum
===========

SPL inspired PHP enum class implementation

4.2.0(2y ago)202.1M—7.6%220MITPHPPHP ^8.0CI passing

Since May 30Pushed 6mo ago6 watchersCompare

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

READMEChangelogDependencies (1)Versions (28)Used By (20)

Konekt Enum
===========

[](#konekt-enum)

[![Tests](https://camo.githubusercontent.com/d0e1c35d3c9679977af4b428ad8b0558dd2cd337deb3e7fe825f78210988b016/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6172746b6f6e656b742f656e756d2f74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/artkonekt/enum/actions?query=workflow%3Atests)[![Packagist Stable Version](https://camo.githubusercontent.com/7867ba7402c7ce549b6ab21eaf3929a64c46260a7b1bc3638f2300e4f72602b6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b6f6e656b742f656e756d2e7376673f7374796c653d666c61742d737175617265266c6162656c3d737461626c65)](https://packagist.org/packages/konekt/enum)[![Packagist downloads](https://camo.githubusercontent.com/c03326780e4b3886ab6b44ca7594d7ee3cfe4ab7e0fa405ff60a7f5c3c1eaef0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b6f6e656b742f656e756d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/konekt/enum)[![StyleCI](https://camo.githubusercontent.com/5da9865802de8c180a46a7aa0be61eba73998787e107be17dbd6cbdd7fdca0e6/68747470733a2f2f7374796c6563692e696f2f7265706f732f36303033363530342f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/60036504)[![MIT Software License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

PHP Enum Class
--------------

[](#php-enum-class)

> Enums are handy when a variable (especially a method parameter) can only take one out of a small set of possible values.

Konekt Enum is a lightweight abstract class that enables creation of PHP enums.

> **Why not PHP 8.1 Enums?** This package was created back in 2013, and has been in use across many libraries. We're planning to find the way to make this package be based on native PHP enums AND keep compatibility with earlier versions as much as possible. This is expected in the **v5.0** release of this package.

### Usage

[](#usage)

Extend the base class and define constants on it:

##### Example

[](#example)

```
class ChessPiece extends \Konekt\Enum\Enum {
    const KING   = 'king';
    const QUEEN  = 'queen';
    const ROOK   = 'rook';
    const BISHOP = 'bishop';
    const KNIGHT = 'knight';
    const PAWN   = 'pawn';
}

var $queen = new ChessPiece('queen');
```

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

[](#installation)

using composer: `composer require konekt/enum`

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

[](#documentation)

For detailed usage and examples go to the [Konekt Enum Documentation](https://konekt.dev/enum) or refer to the markdown files in the `docs/` folder of this repo.

For the list of changes read the [Changelog](Changelog.md).

Upgrade
-------

[](#upgrade)

- From 3.x -&gt; 4.x see [Upgrade to 4.0](https://konekt.dev/enum/4.x/upgrade#from-v3-to-v4)
- From 2.x -&gt; 3.x see [Upgrade to 3.0](https://konekt.dev/enum/4.x/upgrade#from-v2-to-v3)
- From 1.x -&gt; 2.x see [Upgrade to 2.0](https://konekt.dev/enum/4.x/upgrade#from-v1-to-v2)

Laravel Eloquent Integration
----------------------------

[](#laravel-eloquent-integration)

There is a tiny trait for Laravel that helps you to automatically map fields of Eloquent models to/from Enum objects. For more details go to the [konekt/enum-eloquent](https://github.com/artkonekt/enum-eloquent) package.

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance47

Moderate activity, may be stable

Popularity49

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 92.7% 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 ~109 days

Recently: every ~180 days

Total

27

Last Release

809d ago

Major Versions

1.2.x-dev → 2.0.02017-09-13

2.2.x-dev → 3.0.02019-06-24

2.3.x-dev → 3.0.x-dev2019-12-25

3.1.x-dev → 4.0.02022-03-10

PHP version history (5 changes)1.0.0PHP &gt;=5.5.9

2.0.0PHP &gt;=7.0.0

3.0.0PHP ^7.1.3

3.1.0PHP ^7.3 || ^8.0

4.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c398dd02c93ecf6aa344f367f5744aeb32b4c7bbc23b1b22e95336f45bf0d5a?d=identicon)[konekt](/maintainers/konekt)

---

Top Contributors

[![fulopattila122](https://avatars.githubusercontent.com/u/1162360?v=4)](https://github.com/fulopattila122 "fulopattila122 (101 commits)")[![marcmascort](https://avatars.githubusercontent.com/u/3595718?v=4)](https://github.com/marcmascort "marcmascort (4 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (3 commits)")[![sandort](https://avatars.githubusercontent.com/u/6926708?v=4)](https://github.com/sandort "sandort (1 commits)")

---

Tags

enumphp-enumenumkonektartkonekt

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/konekt-enum/health.svg)](https://phpackages.com/packages/konekt-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)[konekt/enum-eloquent

Enum attribute casting for Eloquent models

622.0M11](/packages/konekt-enum-eloquent)

PHPackages © 2026

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