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

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

phpgears/enum
=============

Enum for PHP

0.3(6y ago)019MITPHPPHP ^7.1CI failing

Since Sep 16Pushed 5y ago1 watchersCompare

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

READMEChangelogDependencies (16)Versions (6)Used By (0)

[![PHP version](https://camo.githubusercontent.com/d0b5687c6812c5d52d86a548e09db527eeb7860f82adbb677de00a36ddbed1b4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344372e312d3838393242462e7376673f7374796c653d666c61742d737175617265)](http://php.net)[![Latest Version](https://camo.githubusercontent.com/b535bee1c348608e4b72a150c658c093fef4b04466c54f82e9769e70dfb52eb6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70687067656172732f656e756d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpgears/enum)[![License](https://camo.githubusercontent.com/a08cb9f75b95c53c5fd7d1dbb75fc99fe32b4d8c989fe82d8e2870b3f751c13f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70687067656172732f656e756d2e7376673f7374796c653d666c61742d737175617265)](https://github.com/phpgears/enum/blob/master/LICENSE)

[![Build Status](https://camo.githubusercontent.com/eba89918f303c2c23a13f0c8fc51320755ce2606d79ef8ba0882f4cf89edd204/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f70687067656172732f656e756d2e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.com/github/phpgears/enum)[![Style Check](https://camo.githubusercontent.com/5406d59a867d3d595c223f2faa16aa963ce27fbba626f772e436e6ab84ec2e83/68747470733a2f2f7374796c6563692e696f2f7265706f732f3134383834303938332f736869656c64)](https://styleci.io/repos/148840983)[![Code Quality](https://camo.githubusercontent.com/3f97038125fae2517ae9d8f8d06a4bc0793dfa555f9486198529d2e2196e08c9/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f70687067656172732f656e756d2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/phpgears/enum)[![Code Coverage](https://camo.githubusercontent.com/d757e3e6b99d8227bb224869e0442394176856bce69792423f98811b04d834fa/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f70687067656172732f656e756d2e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/github/phpgears/enum)

[![Total Downloads](https://camo.githubusercontent.com/84648b8c8527f7b85b71f60820c3859684162651008f5587c6f0cf5b814a77d7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70687067656172732f656e756d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpgears/enum/stats)[![Monthly Downloads](https://camo.githubusercontent.com/8a9f37440d0a155ea9b30d2989b919a161b6a10c7839d50daea11ef3a9cad404/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f70687067656172732f656e756d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpgears/enum/stats)

Enum
====

[](#enum)

Immutable Enum objects for PHP

Other languages have the concept of Enum and while there is an extension in PHP for enums it's not available by default or widely spread

The implementation of an Enum class is not so difficult, but it should cover value validation and be immutable so its value cannot be changed

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

[](#installation)

### Composer

[](#composer)

```
composer require phpgears/enum

```

Usage
-----

[](#usage)

Require composer autoload file

```
require './vendor/autoload.php';
```

By extending `Gears\Enum\AbstractEnum` you can easily have Enum classes

```
use Gears\Enum\AbstractEnum;

/**
 * @method static self DAILY()
 * @method static self WEEKLY()
 * @method static self BIWEEKLY()
 * @method static self MONTHLY()
 * @method static self YEARLY()
 */
final class DatePeriod extends AbstractEnum
{
    public const DAILY = 'daily';
    public const WEEKLY = 'weekly';
    public const BIWEEKLY = 'biweekly';
    public const MONTHLY = 'monthly';
    public const YEARLY = 'yearly';
}

$period = new DatePeriod('daily');

$period->getValue() === DatePeriod::DAILY; // true
$period->isEqualTo(DatePeriod::DAILY()); // true
$period->isAnyOf([DatePeriod::DAILY(), DatePeriod::WEEKLY()]); // true

$period->getValue() === DatePeriod::YEARLY; // false
$period->isEqualTo(DatePeriod::MONTHLY()); // false
$period->isAnyOf([DatePeriod::MONTHLY(), DatePeriod::YEARLY()]); // false

$period->getValue(); // daily

$newPeriod = new DatePeriod($period);

$newPeriod->getValue() === DatePeriod::DAILY; // true
$newPeriod->getValue() === $period->getValue(); // true
$newPeriod->isEqualTo($period); // true

$newPeriod->getValue(); // daily
```

Enums **must** always be defined as final

*It is advised to add `@method` annotation references on class docblock for your editor to be able to help you with auto-completion*

Contributing
------------

[](#contributing)

Found a bug or have a feature request? [Please open a new issue](https://github.com/phpgears/enum/issues). Have a look at existing issues before.

See file [CONTRIBUTING.md](https://github.com/phpgears/enum/blob/master/CONTRIBUTING.md)

License
-------

[](#license)

See file [LICENSE](https://github.com/phpgears/enum/blob/master/LICENSE) included with the source code for a copy of the license terms.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

Total

5

Last Release

2260d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4c50421f1ab4148354dc2dd5dcaba168656b17ea913b310d112deb39a6f73ca1?d=identicon)[juliangut](/maintainers/juliangut)

---

Top Contributors

[![juliangut](https://avatars.githubusercontent.com/u/1104131?v=4)](https://github.com/juliangut "juliangut (16 commits)")

---

Tags

enumimmutable

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[myclabs/php-enum

PHP Enum implementation

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

PHP 7.1 enum implementation

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

PHP Enums

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

Simple and fast implementation of enumerations with native PHP

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

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[aeon-php/calendar

PHP type safe, immutable calendar library

2079.7M16](/packages/aeon-php-calendar)

PHPackages © 2026

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