PHPackages                             calabrothers/php-ds-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. calabrothers/php-ds-enum

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

calabrothers/php-ds-enum
========================

PHP Enum Support

1.0.0(6y ago)08MITPHP

Since Jan 19Pushed 6y ago1 watchersCompare

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

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

PHP Enum Support
================

[](#php-enum-support)

[![Build Status](https://camo.githubusercontent.com/9f491fdfb26ef5a00f9100a3e0354d08d808812eff06426d9bd6a2070526a152/68747470733a2f2f7472617669732d63692e6f72672f63616c6162726f74686572732f7068702d64732d656e756d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/calabrothers/php-ds-enum.svg?branch=master) [![Coverage Status](https://camo.githubusercontent.com/d02443da5f68d22fa8cc9ef11faa4c4e6283dde353910483290dec6c80bab184/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f63616c6162726f74686572732f7068702d64732d656e756d2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/calabrothers/php-ds-enum?branch=master) [![Total Downloads](https://camo.githubusercontent.com/4db9ce747b003ed070262e3d409a28bbcee1a0a4c79b5181a2c5db20a6430af1/68747470733a2f2f706f7365722e707567782e6f72672f63616c6162726f74686572732f7068702d64732d656e756d2f646f776e6c6f616473)](https://packagist.org/packages/calabrothers/php-ds-enum) [![License](https://camo.githubusercontent.com/e56ea4a453b2c87d39539f2b8bfdf25f51fab20a93a4ca4c0051c5c529533453/68747470733a2f2f706f7365722e707567782e6f72672f63616c6162726f74686572732f7068702d64732d656e756d2f6c6963656e7365)](https://packagist.org/packages/calabrothers/php-ds-enum)

A collection of classes to support Enum data types.

Install
-------

[](#install)

```
composer require calabrothers/php-ds-enum

```

Test
----

[](#test)

```
composer install
composer test

```

HowTo
-----

[](#howto)

Enum library provides two base classes:

- **Enum**
- **EnumUnique**

### Enum Class

[](#enum-class)

```
use Ds\Enum;

class MyEnum extends Enum {
    public const FOO            = 0;
    public const BAR            = 0;
}

```

As C++, **Enum allows duplicated** values, in this case FOO and BAR. The **MyEnum** internal representation is integer. You can use both classic object constructor as

```
$oObj = new MyEnum(0);

```

or from a factory function:

```
$oObj = MyEnum::FOO();

```

or with a copy constructor:

```
$oObj = new MyEnum(MyEnum::FOO());

```

or from a string:

```
$oObj = MyEnum::fromString('FOO');

```

then you can use classic comparison operator

```
echo ($oObj == MyEnum::FOO() ? "Oh yeah" : "uhm"); // Oh yeah

```

### EnumUnique Class

[](#enumunique-class)

```
use Ds\Enum;

class MyEnumUnique extends EnumUnique {
    public const FOO            = 0;
    public const BAR            = 1;
}

```

For this class

```
$oObj = MyEnumUnique::FOO();
echo ($oObj == MyEnumUnique::FOO() ? "Oh yeah" : "uhm"); // Oh yeah
echo ($oObj == MyEnumUnique::BAR() ? "uhm" : "not bad"); // not bad

```

### Default values

[](#default-values)

Both base classes support **default** value. For example, a unique class with default value will be:

```
use Ds\Enum;

class MyEnumUniqueDef extends EnumUnique {
    public const __DEFAULT__    = 0;
    public const FOO            = 0;
    public const BAR            = 1;
}

```

then you can also use default constructor:

```
$oObj = new MyEnumUniqueDef();
echo ($oObj == MyEnumUniqueDef::FOO() ? "Oh yeah" : "uhm"); // Oh yeah

```

### Credits

[](#credits)

- [Vincenzo Calabrò](www.cybertronics.cloud/vc)

### Support Quality Code

[](#support-quality-code)

[![Foo](https://camo.githubusercontent.com/648ad6f048733f167bf65e11a4fd759eef14da88db61ad078bbd5ddea5d57133/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e6174655f4c472e676966)](https://paypal.me/muawijhe)

### License

[](#license)

The MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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

2307d ago

### Community

Maintainers

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

---

Tags

enumlibraryds

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/calabrothers-php-ds-enum/health.svg)](https://phpackages.com/packages/calabrothers-php-ds-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)[league/iso3166

ISO 3166-1 PHP Library

69536.3M116](/packages/league-iso3166)[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

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

Enumeration (enum) implementation for PHP

48482.2k2](/packages/rexlabs-enum)

PHPackages © 2026

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