PHPackages                             bonndan/phpenums - 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. bonndan/phpenums

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

bonndan/phpenums
================

An experimental Enum implementation for PHP7

0.1.0(9y ago)114PHPPHP ^7

Since Jan 27Pushed 2y agoCompare

[ Source](https://github.com/bonndan/phpenums)[ Packagist](https://packagist.org/packages/bonndan/phpenums)[ RSS](/packages/bonndan-phpenums/feed)WikiDiscussions master Synced yesterday

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

PHP Enums
=========

[](#php-enums)

[![Build Status](https://camo.githubusercontent.com/71ecc8377aef1a3169fdb604064b82c05b132a2610dfd0348a39c35c8d5415e8/68747470733a2f2f7472617669732d63692e6f72672f626f6e6e64616e2f706870656e756d732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bonndan/phpenums)[![Minimum PHP Version](https://camo.githubusercontent.com/5c3072425e67297c8ef63d17acd2c86a0d2ef324f19249f2280bd7de902f63a2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372e302d3838393242462e737667)](https://php.net/)

Yet another implementation of Enums in PHP. The difference to most other implementations is that the implemetation is very close to Java. Static properties are used, but like in Java they are real instances of the Enum providing all methods etc:

```
class Fruit extends \Pava\Enum
{
    /**
     * @var Fruit
     */
    public static $APPLE;

    /**
     * @var Fruit
     */
    public static $BANANA;
}
```

So you can use static typing:
-----------------------------

[](#so-you-can-use-static-typing)

```
$mix = function (Fruit $a, Fruit $b) {};

$blend = $mix(Fruit::$APPLE, Fruit::$BANANA);

$grow = function () : Fruit { return Fruit::$APPLE };

assert(Fruit::$APPLE instanceof Fruit);
```

What are the drawbacks?
-----------------------

[](#what-are-the-drawbacks)

- Each enum has to be registered (unless static constructors arrive in PHP). The reason is that static properties can only have scalar values as default.

```
//class Fruit ...

Pava\register(Fruit::class);
```

- You need to annotate all static props in order to get your IDE working with it, but at least this works.
- No default values usable. At "compile time" $BANANA is not yet an instance. However you can use null as default value.

```
//not possible
$a = function (Fruit $a = Fruit::$BANANA) {};
```

- Use/import is not possible, i.e. you cannot just write $BANANA.

Advanced use
------------

[](#advanced-use)

Each enum instance can obtain its own properties by implementing the magic invoke method.

```
class Fruit extends \Pava\Enum
{
    private $color;

    /**
     * @var Fruit
     */
    public static $APPLE;

    /**
     * @var Fruit
     */
    public static $BANANA;

    public function color() : string
    {
        return $this->color;
    }

    public function __invoke()
    {
        if ($this->name() == 'BANANA')
            $this->color = 'yellow';
        if ($this->name() == 'APPLE')
            $this->color = 'green';
    }
}
Pava\register(Fruit::class);

echo 'The apple is ' . Fruit::$APPLE->color();
```

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 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

3440d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/143695?v=4)[bonndan](/maintainers/bonndan)[@bonndan](https://github.com/bonndan)

---

Top Contributors

[![bonndan](https://avatars.githubusercontent.com/u/143695?v=4)](https://github.com/bonndan "bonndan (5 commits)")

---

Tags

enumphp7

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bonndan-phpenums/health.svg)

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

###  Alternatives

[zenstruck/class-metadata

Add human readable class aliases &amp; metadata with efficient lookups.

142.9k17](/packages/zenstruck-class-metadata)

PHPackages © 2026

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