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

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

dbalabka/php-enumeration
========================

Implementation of Enumeration Classes in PHP. The better alternative for Enums

v0.4.0(6y ago)546994[2 PRs](https://github.com/dbalabka/php-enumeration/pulls)MITPHPPHP &gt;=7.1CI failing

Since Aug 29Pushed 3y ago6 watchersCompare

[ Source](https://github.com/dbalabka/php-enumeration)[ Packagist](https://packagist.org/packages/dbalabka/php-enumeration)[ RSS](/packages/dbalabka-php-enumeration/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (4)Versions (14)Used By (0)

PHP Enumeration classes
=======================

[](#php-enumeration-classes)

[![Build Status](https://camo.githubusercontent.com/8a7ad7c611e79feb46af820ef16cb94996f764e904222daafd7056e078976675/68747470733a2f2f7472617669732d63692e6f72672f6462616c61626b612f7068702d656e756d65726174696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/dbalabka/php-enumeration)[![Coverage Status](https://camo.githubusercontent.com/fb3621e383184b8c32c56c1ea5826f48282c626cbcf036cdc0686d3c32181ab2/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6462616c61626b612f7068702d656e756d65726174696f6e2f62616467652e737667)](https://coveralls.io/github/dbalabka/php-enumeration)

Implementation of [Enumeration Classes](https://docs.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/enumeration-classes-over-enum-types) in PHP. The better alternative for Enums.

In contrast to [existing solutions](#existing-solutions), this implementation avoids usage of [Magic methods](https://www.php.net/manual/en/language.oop5.magic.php) and [Reflection](https://www.php.net/manual/en/book.reflection.php) to provide better performance and code autocompletion. The Enumeration class holds a reference to a single Enum element represented as an object (singleton) to provide the possiblity to use strict (`===`) comparision between the values. Also, it uses static properties that can utilize the power of [Typed Properties](https://wiki.php.net/rfc/typed_properties_v2). The Enumeration Classes are much closer to other language implementations like [Java Enums](https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html)and [Python Enums](https://docs.python.org/3/library/enum.html).

Declaration
-----------

[](#declaration)

A basic way to declare a named Enumeration class:

```
