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

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

jesseschalken/enum
==================

PHP Enums without using Reflection

v1.0(10y ago)018MITPHP

Since Jan 15Pushed 10y ago1 watchersCompare

[ Source](https://github.com/jesseschalken/php-enum)[ Packagist](https://packagist.org/packages/jesseschalken/enum)[ RSS](/packages/jesseschalken-enum/feed)WikiDiscussions master Synced 3w ago

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

php-enum
========

[](#php-enum)

Fast and safe enums for PHP 5.3+ without using reflection.

Objectives:

- Be fast. Checking an enum value should be *O(1)*.
- Be concise. The author of the enum should have to write as minimal code as possible without compromising the other objectives.
- Be safe. An instance of the concrete Enum class may only contain a valid value.
- Without Reflection. In particular:
    - Don't use `ReflectionClass` to get a list of a class's constants, since this violates the developer's expectation that a class constant not referenced via `Class::CONSTANT` is unused and can be removed.
    - Don't use `__call` or `__callStatic` to create pseudo-methods, since this violates the developer's expectation that a call to a method of the form `Class::method()` or `$object->method()` which cannot be found in the code is an error.

Example:

```
use JesseSchalken\Enum\IntEnum;

class Day extends IntEnum {
	const MONDAY    = 0;
    const TUESDAY   = 1;
    const WEDNESDAY = 2;
    const THURSDAY  = 3;
    const FRIDAY    = 4;
    const SATURDAY  = 5;
    const SUNDAY    = 6;

    public static function values() {
    	return array(
        	self::MONDAY,
        	self::TUESDAY,
        	self::WEDNESDAY,
        	self::THURSDAY,
        	self::FRIDAY,
        	self::SATURDAY,
        	self::SUNDAY,
        );
    }
}

function needs_day(Day $d) {
    if ($d->value() == Day::FRIDAY) {
    	print "It's Friday, Friday...";
    }
}

Day::check(Day::TUESDAY); // okay
Day::check(2); // okay
Day::check(7); // throws EnumException

Day::valid(Day::SUNDAY); // true
Day::valid('foo'); // false

$day = new Day(Day::MONDAY);

needs_day($day);
```

```
use JesseSchalken\Enum\StringEnum;

class Color extends StringEnum {
    const RED    = 'red';
    const ORANGE = 'orange';
    const YELLOW = 'yellow';
    const GREEN  = 'green';
    const BLUE   = 'blue';
    const PURPLE = 'purple';

	public static function values() {
    	return array(
            self::RED,
            self::ORANGE,
            self::YELLOW,
            self::GREEN,
            self::BLUE,
            self::PURPLE,
        );
    }
}

function needs_color(Color $c) {
	switch ($c->value()) {
    	case Color::RED:
        	print 'is red';
            break;
       	//...
    }
}

$color = new Color(Color::RED);

needs_color($color);
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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

Unknown

Total

1

Last Release

3818d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1559204?v=4)[Jesse Schalken](/maintainers/jesseschalken)[@jesseschalken](https://github.com/jesseschalken)

---

Top Contributors

[![jesseschalken](https://avatars.githubusercontent.com/u/1559204?v=4)](https://github.com/jesseschalken "jesseschalken (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mediconesystems/livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS

1.2k722.0k8](/packages/mediconesystems-livewire-datatables)[freedsx/asn1

An ASN.1 library for PHP.

15236.9k13](/packages/freedsx-asn1)[mmerian/phpcrawl

PHPCrawl is a webcrawler/webspider-library written in PHP. It supports filters, limiters, cookie-handling, robots.txt-handling, multiprocessing and much more.

597.1k](/packages/mmerian-phpcrawl)[johndoh/sauserprefs

Control SpamAssassin settings from within Roundcube

563.7k](/packages/johndoh-sauserprefs)[danog/phpstruct

PHP implementation of python's struct module.

1110.5k](/packages/danog-phpstruct)

PHPackages © 2026

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