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

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

nelexa/enum
===========

PHP Enum implementation

1.1.1(5y ago)1525.3k↓56.3%4MITPHPPHP ^7.1|^8.0

Since May 14Pushed 5y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (1)Versions (6)Used By (4)

nelexa/enum - Enum implementation for PHP
=========================================

[](#nelexaenum---enum-implementation-for-php)

[![Packagist Version](https://camo.githubusercontent.com/296f5eaa4be8f8131905f92745dd26c88d2c79018aa3f585d3fbb9e1028ce24a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e656c6578612f656e756d2e737667)](https://packagist.org/packages/nelexa/enum)[![Packagist](https://camo.githubusercontent.com/ace00d4f04e62d44a0f79006ad41ffd71f56d7f1a26abee9b3f46f110dc7c0ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e656c6578612f656e756d2e7376673f636f6c6f723d253233666630303766)](https://packagist.org/packages/nelexa/enum)[![Build Status](https://github.com/Ne-Lexa/enum/workflows/build/badge.svg)](https://github.com/Ne-Lexa/enum/actions)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/712df41d1fbe9f7ea12a9cca22d3c175d888e82fedfec9ab5c29f95a8033cbb7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4e652d4c6578612f656e756d2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Ne-Lexa/enum/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/de2a39ada4ba5b2a0071ce7606902ebb07e614da863f6bf53d082da3e110b451/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4e652d4c6578612f656e756d2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Ne-Lexa/enum/?branch=master)[![Build Status](https://camo.githubusercontent.com/37e3613b76f21108075ea4fb01ebc9c1b9a40f9df6d2bd0a6480b0ae1c249a14/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4e652d4c6578612f656e756d2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Ne-Lexa/enum/build-status/master)[![License](https://camo.githubusercontent.com/ba35c041d97b107ceb8a010df7d5d8b171c1cb625eca4f1ed8d25e31145a052e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e656c6578612f656e756d2e737667)](https://packagist.org/packages/nelexa/enum)

Table of Contents
=================

[](#table-of-contents)

- [nelexa/enum - Enum implementation for PHP](#nelexaenum---enum-implementation-for-php)
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [Enum declaration](#enum-declaration)
- [Usage](#usage)
    - [To loop a enum object](#to-loop-a-enum-object)
    - [To compare the enum values, use === operator](#to-compare-the-enum-values-use--operator)
    - [Convert a string to enum object](#convert-a-string-to-enum-object)
    - [Convert a value to enum object](#convert-a-value-to-enum-object)
    - [Switch case](#switch-case)
    - [Use enum in the type hint](#use-enum-in-the-type-hint)
    - [Add some logic to enum](#add-some-logic-to-enum)
    - [Initialization of values ​​without constructor](#initialization-of-values-without-constructor)
- [Class Synopsis](#class-synopsis)
- [Usage tips](#usage-tips)
- [Generate PHPDoc for enum class](#generate-phpdoc-for-enum-class)
- [Changelog](#changelog)
- [License](#license)

Installation
============

[](#installation)

```
composer require nelexa/enum
```

Enum declaration
================

[](#enum-declaration)

```
