PHPackages                             codinc/phpenum - 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. codinc/phpenum

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

codinc/phpenum
==============

A simple PHP Enum implementation, as an alternative to SplEnum

1.0.3(8y ago)0254Apache-2.0PHPPHP &gt;=7.1.0

Since May 16Pushed 8y agoCompare

[ Source](https://github.com/CodincBe/phpEnum)[ Packagist](https://packagist.org/packages/codinc/phpenum)[ Docs](http://www.codinc.be)[ RSS](/packages/codinc-phpenum/feed)WikiDiscussions master Synced 4d ago

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

phpEnum
=======

[](#phpenum)

A simple PHP Enum implementation, as an alternative to SplEnum, allowing typesafety for values belonging to an enum.

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

[](#installation)

`composer require codinc/phpenum`

Usage
-----

[](#usage)

The abstract class supports extension by concrete classes that define constants as valid values.

```
use Codinc\Type\Enum;

class MyEnum extends Enum
{
    const PERSONAL = 'personal';
    const TEAM = 'team';
}

```

Of course, the biggest advantage of an enum is to allow typehinting and built-in safety on methods on your set of values.

```
public function doAnAction(MyEnum $value)
{
    // Can only contain PERSONAL or TEAM
}

```

The biggest advantage and difference of this implementation is that it is allowing native strict comparison. The Enum keeps track of the instantiated objects to ensure only one instance can be used.

```
MyEnum::PERSONAL() === MyEnum::PERSONAL(); // === true

```

It is supported to call the constant as a method without added overhead. In case you do desire the benefits of autocompletion, or desire to protect your constants, you can still define the public static methods yourself and call load on the Enum.

```
use Codinc\Type\Enum;

class MyEnum extends Enum
{
    const PERSONAL = 'personal';
    const TEAM = 'team';
    const WORLD = 'world';
    private const COMPANY = 'company';

    public static function WORLD()
    {
        return self::load(self::WORLD);
    }

    public static function COMPANY()
    {
        return self::load(self::COMPANY);
    }
}

```

```
$personal = MyEnum::PERSONAL();
$world = MyEnum::WORLD();

```

Unsupported values will throw an \\InvalidArgumentException.

```
MyEnum::load('personal'); // === MyEnum::PERSONAL()
MyEnum::load('made_up'); // throws \InvalidArgumentException
MyEnum::load($repository->fetchColumn($column));

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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

Every ~0 days

Total

4

Last Release

2921d ago

### Community

Maintainers

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

---

Top Contributors

[![jandeschuttere](https://avatars.githubusercontent.com/u/741097?v=4)](https://github.com/jandeschuttere "jandeschuttere (8 commits)")

---

Tags

phpenumstricttypesafety

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/codinc-phpenum/health.svg)

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

###  Alternatives

[strictus/strictus

Strict Typing for local variables in PHP

1606.9k](/packages/strictus-strictus)[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)[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)
