PHPackages                             garoevans/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. garoevans/php-enum

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

garoevans/php-enum
==================

Convenient way to always have an Enum object available and utilise Spl Types if available.

1.2.0(11y ago)19158.8k—7%2[2 issues](https://github.com/garoevans/php-enum/issues)5MITPHPPHP &gt;=5.4

Since Feb 5Pushed 10y ago4 watchersCompare

[ Source](https://github.com/garoevans/php-enum)[ Packagist](https://packagist.org/packages/garoevans/php-enum)[ Docs](https://github.com/garoevans/php-enum)[ RSS](/packages/garoevans-php-enum/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (13)Used By (5)

Garoevans Php Enum [![Build Status](https://camo.githubusercontent.com/bfbaf464ff378a084b91ff35f541625bd363167715b7c51faae5947926336edf/68747470733a2f2f7472617669732d63692e6f72672f6761726f6576616e732f7068702d656e756d2e706e67)](https://travis-ci.org/garoevans/php-enum)
============================================================================================================================================================================================================================================================================

[](#garoevans-php-enum-)

This gives us a convenient way to always have an Enum object available and utilise Spl Types if available. It does kick up a bit of a fuss in some IDEs as it sees two classes with the same name, but we know this isn't an issue as the code is fine and dandy :)

We also wrap the SplEnum class to stop IDEs thinking that the constructor parameters are necessary. Force it to act like the documentation says it should.

The replacement is so closely tied to the expected usage of the Spl Enum that you could just use the  documentation;

```
use Garoevans\PhpEnum\Enum;

class Fruit extends Enum
{
    // If no value is given during object construction this value is used
    const __default = self::APPLE;
    // Our enum values
    const APPLE     = 1;
    const ORANGE    = 2;
}

$myApple  = new Fruit();
$myOrange = new Fruit(Fruit::ORANGE);
$fail     = 1;

function eat(Fruit $aFruit)
{
    if ($aFruit->is(Fruit::APPLE)) {
        echo "Eating an apple.\n";
    } else if ($aFruit->is(Fruit::ORANGE)) {
        echo "Eating an orange.\n";
    }
}

// Eating an apple.
eat($myApple);
// Eating an orange.
eat($myOrange);

// PHP Catchable fatal error:  Argument 1 passed to eat() must be an
// instance of Fruit, integer given
eat($fail);
```

Apart from normalizing the Spl Enum construct there are additions including a shorthand way of instantiating via a static method named the same as the desired constant. Using the `Fruit` class from above we can do the following;

```
// Eating an apple.
eat(Fruit::APPLE());
```

Also, the `constantExists()` method is available for use;

```
$fruit = new Fruit();
if ($fruit->constantExists("apple")) {
    echo "Apple is available.\n";
}
```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity65

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 ~76 days

Recently: every ~129 days

Total

9

Last Release

4239d ago

PHP version history (2 changes)v1.0.1PHP &gt;=5

1.2.0PHP &gt;=5.4

### Community

Maintainers

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

---

Top Contributors

[![garoevans](https://avatars.githubusercontent.com/u/1016708?v=4)](https://github.com/garoevans "garoevans (41 commits)")

---

Tags

phptypeenumenumerationsplenum

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

49644.8M97](/packages/marc-mabe-php-enum)[rexlabs/enum

Enumeration (enum) implementation for PHP

48482.2k2](/packages/rexlabs-enum)[aldemeery/enum-polyfill

A Polyfill for the SplEnum type in PHP

1156.6k](/packages/aldemeery-enum-polyfill)[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)[strictus/strictus

Strict Typing for local variables in PHP

1606.9k](/packages/strictus-strictus)

PHPackages © 2026

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