PHPackages                             dreamscapes/enumeration - 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. dreamscapes/enumeration

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

dreamscapes/enumeration
=======================

A simple Typedef Enum implementation for php

1.0.0(11y ago)378101BSD-3-ClausePHPPHP &gt;=5.4.0

Since Oct 26Pushed 11y ago1 watchersCompare

[ Source](https://github.com/Dreamscapes/Enumeration)[ Packagist](https://packagist.org/packages/dreamscapes/enumeration)[ Docs](https://github.com/Dreamscapes/Enumeration)[ RSS](/packages/dreamscapes-enumeration/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (8)Dependencies (4)Versions (10)Used By (1)

Enumerations for PHP
====================

[](#enumerations-for-php)

[![Build Status](https://camo.githubusercontent.com/acca912770b68a3c741987ed5fc2ad958b46823f14df37489fac07b4fe75b139/68747470733a2f2f6170692e7472617669732d63692e6f72672f447265616d7363617065732f456e756d65726174696f6e2e706e67)](https://travis-ci.org/Dreamscapes/Enumeration)[![Coverage Status](https://camo.githubusercontent.com/d271e12fb44a5fca3b220bf9f92c11f0726a2c5b7e0ff0053f4d6a900f2e2d38/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f447265616d7363617065732f456e756d65726174696f6e2e737667)](https://coveralls.io/r/Dreamscapes/Enumeration?branch=develop)[![Dependency Status](https://camo.githubusercontent.com/05f9131f4786f8a7b08d7eba7c22b880827c094ed5e2bc7b9177d80c78ff6fd7/68747470733a2f2f67656d6e617369756d2e636f6d2f447265616d7363617065732f456e756d65726174696f6e2e706e67)](https://gemnasium.com/Dreamscapes/Enumeration)

Every php programmer at some point wants to put some structure to all those constants defined in their code. Usually one would put those constants under a dedicated class, but that's it; no additional features, no real benefit, no nothing.

What if you could get more?
---------------------------

[](#what-if-you-could-get-more)

This small library aims at providing additional features to your "Enumerations" - a set of static values that represent something meaningful to your code.

The problem with constants
--------------------------

[](#the-problem-with-constants)

Let's say our program will work with animals - various different animals, and we would like each type of animal to have a distinct value ( which I completely made up in this example ). Here's what many programmers currently do:

```
define('MYAPP_ANIMAL_HORSE', 0);
define('MYAPP_ANIMAL_DOG', 1);
define('MYAPP_ANIMAL_CAT', 2);
// ...
```

While this certaily works, there is a better way of defining those.

```
namespace MyApp;

class Animal
{
  const Horse = 0;
  const Dog = 1;
  const Cat = 2;
}
```

Defining the constants as a class has several benefits:

1. You can use real namespacing, which can save you a few typing when using the class
2. It feels more natural to use `Animal::Horse` than `MYAPP_ANIMAL_HORSE`
3. Since it's a class it opens up new possibilities and ideas -&gt; that's where this library comes to use :)

How this library helps
----------------------

[](#how-this-library-helps)

The above example with a class introduces some issues but also opens up new possibilities.

1. There's nothing preventing the programmer from instantiating the class
2. What if you wanted to do it the opposite way? -&gt; you have a value and you want to know the constant's name that holds such value in the enumeration?
3. What if you wanted to check if a constant is defined in the Enumeration?
4. What if you wanted to type-hint an enumerated value in a function/method's parameter list?

Let's take a look at another example that demonstrates the use of **Enumerations** provided by this library.

```
namespace MyApp;

// Let's extend our Enumeration class
class Animal extends \Dreamscapes\Enumeration
{
  const Horse = 0;
  const Dog = 1;
  const Cat = 2;
}

// So far looks the same, but watch now...

$animal = new Animal; // Raises fatal error (private constructor)

Animal::isDefined('Horse'); // Returns (bool)true
Animal::isDefined('Cow'); // Returns (bool)false

// "Reverse resolution"
$value = Animal::Dog;
echo Animal::getName($value); // prints (string)"Dog"

// Type-hinting
function doSomething(Animal $animal)
{
  // $animal is now an instance of the Animal class
  // that can be easily represented as string
  echo $animal;
}
doSomething(Animal::Horse()); // prints (string)"Horse"

// To get the actual value
$value = $animal->value();
// Or, use the Enumeration::getValue() class method
$value = Animal::getValue($animal);
```

As you can see, suddenly there's much more you can possibly do with a class as simple as enumeration can be. Learn more in the [API Docs](http://dreamscapes.github.io/Enumeration) which also include code examples and full method descriptions.

### Semantic methods

[](#semantic-methods)

Enumeration contains several semantically named methods you can use to write code that can be understood simply by looking at the code.

Consider following example:

```
if (Animal::defines('Horse')) {
  // Animal::Horse is defined!
}

echo Animal::withValue(0); // Horse

```

More methods are available - be sure to check out [API Docs](http://dreamscapes.github.io/Enumeration)!

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

[](#installation)

### Via Composer:

[](#via-composer)

`composer require dreamscapes\enumeration:dev-master`

Composer's autoloading is supported so as long as you `require "vendor/autoload.php";` somewhere in your code you can simply start using it.

Documentation
-------------

[](#documentation)

[API documentation](http://dreamscapes.github.io/Enumeration) is available online - it includes all public methods you can use and also several code samples and use cases.

### Offline documentation

[](#offline-documentation)

Sure! Just install the development dependencies and generate the docs.

```
composer require --dev dreamscapes\enumeration:dev-master
php vendor/bin/phpdoc.php

```

Documentation is now available at *./docs/index.html*.

License
-------

[](#license)

This software is licensed under the **BSD (3-Clause) License**. See the [LICENSE](LICENSE) file for more information.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

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

Recently: every ~80 days

Total

8

Last Release

4276d ago

Major Versions

0.3.3 → 1.0.02014-10-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/4300d8bf145f9d0db6e15c90199842aad7541376402c2fc2ee86539631100bc4?d=identicon)[Alaneor](/maintainers/Alaneor)

---

Top Contributors

[![robertrossmann](https://avatars.githubusercontent.com/u/3058150?v=4)](https://github.com/robertrossmann "robertrossmann (62 commits)")

---

Tags

enumenumerationconstanttypedefstatic list

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

49753.5M104](/packages/marc-mabe-php-enum)[cerbero/enum

Zero-dependencies package to supercharge enum functionalities.

359227.5k2](/packages/cerbero-enum)[cerbero/laravel-enum

Laravel package to supercharge enum functionalities.

18995.6k](/packages/cerbero-laravel-enum)[emreyarligan/enum-concern

A PHP package for effortless Enumeration handling with Laravel Collections 📦 ✨

21260.4k2](/packages/emreyarligan-enum-concern)[rexlabs/enum

Enumeration (enum) implementation for PHP

47502.6k2](/packages/rexlabs-enum)[thunderer/platenum

PHP enum library

36146.7k](/packages/thunderer-platenum)

PHPackages © 2026

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