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

ActiveLibrary

tebru/enum
==========

Simple enum library for PHP

v0.5.0(9y ago)3510↓100%2[1 PRs](https://github.com/tebru/enum/pulls)MITPHPPHP &gt;= 5.4

Since Nov 30Pushed 7y ago1 watchersCompare

[ Source](https://github.com/tebru/enum)[ Packagist](https://packagist.org/packages/tebru/enum)[ RSS](/packages/tebru-enum/feed)WikiDiscussions master Synced today

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

[![Build Status](https://camo.githubusercontent.com/b8369dcae1a571adc6814fa053da812184575d1874a632ad74b8cbf05893a90a/68747470733a2f2f7472617669732d63692e6f72672f74656272752f656e756d2e737667)](https://travis-ci.org/tebru/enum)[![Code Coverage](https://camo.githubusercontent.com/e2fad1601406fffe3efbe317e250da977bf30b663ec8986f691710939d1e2bf1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f74656272752f656e756d2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tebru/enum/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/62c6b9b24e4059361ad94fb1ac16a4c3164d0cbc43cae6272f854d2a998c2fa4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f74656272752f656e756d2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tebru/enum/?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/f20e6f724a70dc4ebb0340fd32abeae8bc92e57076aee476d303c76c8ac04cf9/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f36643631313163332d643636382d346333612d393632302d3032616435303462323361342f6d696e692e706e67)](https://insight.sensiolabs.com/projects/6d6111c3-d668-4c3a-9620-02ad504b23a4)

Enum
====

[](#enum)

A simple PHP library to add support for enums. This requires slightly more work than myclabs/php-enum, but does not require reflection. It also forces enums to be singletons.

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

[](#installation)

```
composer require tebru/enum

```

Usage
-----

[](#usage)

To use, extend `AbstractEnum` and implement the getConstants() method.

```
class DirectionEnum extends AbstractEnum
{
    const NORTH = 'north';
    const EAST = 'east';
    const SOUTH = 'south';
    const WEST = 'west';

    /**
     * Return an array of enum class constants
     *
     * @return array
     */
    public static function getConstants()
    {
        return [
            self::NORTH,
            self::EAST,
            self::SOUTH,
            self::WEST,
        ];
    }
}

```

Now you can create a new instance using the static method.

```
DirectionEnum::create('north');

```

You can also create an instance using the \_\_callStatic magic method.

```
DirectionEnum::NORTH();

```

Add a hint to the enum doc block

```
/**
 * @method static $this NORTH()
 */

```

Reference
---------

[](#reference)

There are multiple methods available on each enum

- `create()` \[static\] Returns an instance of the enum
- `values()` \[static\] A 0-indexed array of all of the enum values
- `exists($value)` \[static\] Returns true if the value exists
- `toArray()` \[static\] Returns a hash with keys and values as the enum values
- `equals($enum)` Performs a strict comparison of two enum values
- `getValue()` Returns the current value of the enum
- `__toString()` Same as `getValue()`

###  Health Score

28

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96% 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 ~71 days

Recently: every ~35 days

Total

7

Last Release

3334d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1831497?v=4)[Nate Brunette](/maintainers/natebrunette)[@natebrunette](https://github.com/natebrunette)

---

Top Contributors

[![natebrunette](https://avatars.githubusercontent.com/u/1831497?v=4)](https://github.com/natebrunette "natebrunette (24 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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