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

ActiveLibrary

gusarov112/php-enum
===================

PHP Enum implementation. MyClabs fork

v2.0.0(5y ago)071MITPHPPHP &gt;=7.1

Since Jul 18Pushed 5y agoCompare

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

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

PHP Enum implementation inspired from SplEnum
=============================================

[](#php-enum-implementation-inspired-from-splenum)

Why?
----

[](#why)

First, and mainly, `SplEnum` is not integrated to PHP, you have to install the extension separately.

Using an enum instead of class constants provides the following advantages:

- You can use an enum as a parameter type: `function setAction(Action $action) {`
- You can use an enum as a return type: `function getAction() : Action {`
- You can enrich the enum with methods (e.g. `format`, `parse`, …)
- You can extend the enum to add new values (make your enum `final` to prevent it)
- You can get a list of all the possible values (see below)

This Enum class is not intended to replace class constants, but only to be used when it makes sense.

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

[](#installation)

```
composer require gusarov112/php-enum
```

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

[](#declaration)

```
use Gusarov112\Enum\Enum;

/**
 * Action enum
 */
class Action extends Enum
{
    private const VIEW = 'view';
    private const EDIT = 'edit';
}
```

Usage
-----

[](#usage)

```
$action = new Action(Action::VIEW);
```

One advantage over using class constants is to be able to use an enum as a parameter type:

```
function setAction(Action $action) {
    // ...
}
```

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

[](#documentation)

- `__construct()` The constructor checks that the value exist in the enum
- `__toString()` You can `echo $myValue`, it will display the enum value (value of the constant)
- `getValue()` Returns the current value of the enum
- `getKey()` Returns the key of the current value on Enum
- `equals()` Tests whether enum instances are equal (returns `true` if enum values are equal, `false` otherwise)

Static methods:

- `toArray()` method Returns all possible values as an array (constant name in key, constant value in value)
- `keys()` Returns the names (keys) of all constants in the Enum class
- `values()` Returns instances of the Enum class of all Enum constants (constant name in key, Enum instance in value)
- `isValid()` Check if tested value is valid on enum set
- `isValidKey()` Check if tested key is valid on enum set
- `search()` Return key for searched value

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

2127d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6aa671506ecf4f8a9adf9994926720a4d61bd17afba2645b78704d4f72819d85?d=identicon)[gusarov](/maintainers/gusarov)

---

Top Contributors

[![mnapoli](https://avatars.githubusercontent.com/u/720328?v=4)](https://github.com/mnapoli "mnapoli (87 commits)")[![gusarov112](https://avatars.githubusercontent.com/u/1829821?v=4)](https://github.com/gusarov112 "gusarov112 (15 commits)")[![jarstelfox](https://avatars.githubusercontent.com/u/857362?v=4)](https://github.com/jarstelfox "jarstelfox (11 commits)")[![KartaviK](https://avatars.githubusercontent.com/u/5941637?v=4)](https://github.com/KartaviK "KartaviK (11 commits)")[![peter-gribanov](https://avatars.githubusercontent.com/u/1954436?v=4)](https://github.com/peter-gribanov "peter-gribanov (10 commits)")[![mirfilip](https://avatars.githubusercontent.com/u/1812341?v=4)](https://github.com/mirfilip "mirfilip (7 commits)")[![jeremykendall](https://avatars.githubusercontent.com/u/288613?v=4)](https://github.com/jeremykendall "jeremykendall (6 commits)")[![lorenzomar](https://avatars.githubusercontent.com/u/612386?v=4)](https://github.com/lorenzomar "lorenzomar (4 commits)")[![danielcosta](https://avatars.githubusercontent.com/u/42549?v=4)](https://github.com/danielcosta "danielcosta (4 commits)")[![BernardoSilva](https://avatars.githubusercontent.com/u/1537510?v=4)](https://github.com/BernardoSilva "BernardoSilva (3 commits)")[![chriseskow](https://avatars.githubusercontent.com/u/19055?v=4)](https://github.com/chriseskow "chriseskow (3 commits)")[![garoevans](https://avatars.githubusercontent.com/u/1016708?v=4)](https://github.com/garoevans "garoevans (3 commits)")[![remicollet](https://avatars.githubusercontent.com/u/270445?v=4)](https://github.com/remicollet "remicollet (3 commits)")[![KKKas](https://avatars.githubusercontent.com/u/60153?v=4)](https://github.com/KKKas "KKKas (2 commits)")[![grogy](https://avatars.githubusercontent.com/u/1322983?v=4)](https://github.com/grogy "grogy (1 commits)")[![Ex3v](https://avatars.githubusercontent.com/u/2785665?v=4)](https://github.com/Ex3v "Ex3v (1 commits)")[![drmonkeyninja](https://avatars.githubusercontent.com/u/357623?v=4)](https://github.com/drmonkeyninja "drmonkeyninja (1 commits)")[![drealecs](https://avatars.githubusercontent.com/u/209984?v=4)](https://github.com/drealecs "drealecs (1 commits)")[![osavchenko](https://avatars.githubusercontent.com/u/617002?v=4)](https://github.com/osavchenko "osavchenko (1 commits)")[![Danack](https://avatars.githubusercontent.com/u/1505719?v=4)](https://github.com/Danack "Danack (1 commits)")

---

Tags

enum

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[myclabs/php-enum

PHP Enum implementation

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

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[dasprid/enum

PHP 7.1 enum implementation

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

PHP Enums

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

Simple and fast implementation of enumerations with native PHP

49444.8M97](/packages/marc-mabe-php-enum)[fresh/doctrine-enum-bundle

Provides support of ENUM type for Doctrine2 in Symfony applications.

4636.8M12](/packages/fresh-doctrine-enum-bundle)

PHPackages © 2026

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