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

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

phpenum/phpenum
===============

PHP Enum

v1.4.0(5y ago)702.0k41GPL-3.0PHPPHP &gt;=5.6CI failing

Since Jun 1Pushed 5y ago1 watchersCompare

[ Source](https://github.com/yinfuyuan/php-enum)[ Packagist](https://packagist.org/packages/phpenum/phpenum)[ Docs](https://github.com/yinfuyuan/php-enum)[ Fund](https://github.com/yinfuyuan/php-enum)[ GitHub Sponsors](https://github.com/yinfuyuan)[ RSS](/packages/phpenum-phpenum/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (6)Used By (1)

PHP Enum
========

[](#php-enum)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5cc0045f3447544a84d98bbf8acd54389162f81ae87987f5deec3073c023492d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706870656e756d2f706870656e756d2e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/phpenum/phpenum)[![License](https://camo.githubusercontent.com/ce34bf36d6ee967af7b4f002db13b37320b6a77bdf3ea11e18842cf6a2307779/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f79696e66757975616e2f7068702d656e756d3f7374796c653d666f722d7468652d6261646765)](https://github.com/yinfuyuan/php-enum/blob/master/LICENSE)[![Postcardware](https://camo.githubusercontent.com/97c40bd733ff9974edecedb00f50f1815339c1fbdaedfdc8930069791979c9ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506f737463617264776172652d2546302539462539322538432d3139373539333f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/97c40bd733ff9974edecedb00f50f1815339c1fbdaedfdc8930069791979c9ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506f737463617264776172652d2546302539462539322538432d3139373539333f7374796c653d666f722d7468652d6261646765)

[![PHP from Packagist](https://camo.githubusercontent.com/fc4983f7eec24b6268e1ebfdd02c520be380e780d3bc9d65dc71f781b3421d42/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706870656e756d2f706870656e756d3f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpenum/phpenum)[![Build Status](https://camo.githubusercontent.com/d107867daa4e5ec2e04c6e977e9ccc1e779431f30cbd0009acd22b74bcd6707b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f79696e66757975616e2f7068702d656e756d2f74657374733f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/yinfuyuan/php-enum/actions?query=workflow%3Atests)[![Total Downloads](https://camo.githubusercontent.com/1681814d00e28a2225414eccf285999a693f8a9a79a9f03b5c9ff807708211d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706870656e756d2f706870656e756d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpenum/phpenum)

PHPEnum is an enumeration class library for PHP developers. The idea comes from [Java enumeration](https://docs.oracle.com/javase/8/docs/api/java/lang/Enum.html), and using the PHP features to implement single-value enumeration and multi-value enumeration. PHPEnum runs in most PHP applications.

### Installation

[](#installation)

```
composer require phpenum/phpenum

```

### Getting Started

[](#getting-started)

Using PhpEnum is very similar to using Java Enum, For example, define an enumeration representing gender.

In Java:

```
public enum GenderEnum {
    MALE(1, "male"),
    FEMALE(2, "female");

    private Integer id;
    private String name;

    GenderEnum(Integer id, String name) {
        this.id = id;
        this.name = name;
    }

    public Integer getId() {
        return id;
    }

    public String getName() {
        return name;
    }
}

```

In PHP:

```
class GenderEnum extends \PhpEnum\Enum
{
    const MALE = [1, 'male'];
    const FEMALE = [2, 'female'];

    private $id;
    private $name;

    protected function construct($id, $name)
    {
        $this->id = $id;
        $this->name = $name;
    }

    public function getId()
    {
        return $this->id;
    }

    public function getName()
    {
        return $this->name;
    }
}

```

You'll also find a lot of similarities when using enumerations

In Java:

```
GenderEnum.values(); // enum instance array
GenderEnum.valueOf("FEMALE"); // enum instance
GenderEnum.MALE.equals(GenderEnum.valueOf("MALE")); // true
GenderEnum.MALE.name(); // MALE
GenderEnum.MALE.ordinal(); // 0
GenderEnum.MALE.toString(); // MALE
GenderEnum.MALE.getId(); // 1
GenderEnum.MALE.getName(); // male

```

In PHP:

```
GenderEnum::values(); // enum instance array
GenderEnum::valueOf('FEMALE'); // enum instance
GenderEnum::MALE()->equals(GenderEnum::valueOf('MALE')); // true
GenderEnum::MALE()->name(); // MALE
GenderEnum::MALE()->ordinal(); // 0
(string)GenderEnum::MALE(); // MALE
GenderEnum::MALE()->getId(); // 1
GenderEnum::MALE()->getName(); // male

```

Not only that, PhpEnum also provides advanced functionality in subclasses

```
GenderEnum::MALE()->idEquals(1); // true
GenderEnum::MALE()->NameEquals('male'); // true
GenderEnum::containsId(1); // 1
GenderEnum::containsName('male'); // 1
GenderEnum::ofId(1); // enum instance
GenderEnum::ofName('male'); // enum instance

```

### Documentation

[](#documentation)

PhpEnum supports PHP version 5.6+. The documentation for PHPEnum is available on the [Github wiki](https://github.com/yinfuyuan/php-enum/wiki).

### License

[](#license)

The PHPEnum is open-sourced software licensed under the [GPL-3.0 license](https://github.com/yinfuyuan/php-enum/blob/master/LICENSE).

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community12

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

Every ~56 days

Total

5

Last Release

1953d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9557b8d9ade17b311c7ef015a3c94d0ccc31822d6eeb46d964013e51e605af6b?d=identicon)[yinfuyuan](/maintainers/yinfuyuan)

---

Top Contributors

[![yinfuyuan](https://avatars.githubusercontent.com/u/19318756?v=4)](https://github.com/yinfuyuan "yinfuyuan (27 commits)")

---

Tags

enumenumerationphp-enumenumphpenum

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[myclabs/php-enum

PHP Enum implementation

2.7k227.9M637](/packages/myclabs-php-enum)[dasprid/enum

PHP 7.1 enum implementation

382146.0M11](/packages/dasprid-enum)[spatie/enum

PHP Enums

84529.1M68](/packages/spatie-enum)[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

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

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[consistence/consistence

Consistence - consistent approach and additions to PHP's functionality

1831.1M18](/packages/consistence-consistence)

PHPackages © 2026

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