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

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

kuria/enum
==========

Emulated enumeration objects in PHP

v5.1.0(7y ago)18.2k↓22.2%MITPHPPHP &gt;=7.1

Since Aug 24Pushed 3y ago1 watchersCompare

[ Source](https://github.com/kuria/enum)[ Packagist](https://packagist.org/packages/kuria/enum)[ RSS](/packages/kuria-enum/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (10)Used By (0)

Enum
====

[](#enum)

Emulated enumeration objects in PHP.

The interface is similar to [SplEnum](http://php.net/manual/en/class.splenum.php)but doesn't require any PHP extensions and provides more functionality.

[![https://travis-ci.com/kuria/enum.svg?branch=master](https://camo.githubusercontent.com/e545bd53d52134f6d377321c2f77a008a1817e48eb6d4a35f3e54b7ec69458c2/68747470733a2f2f7472617669732d63692e636f6d2f6b757269612f656e756d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/kuria/enum)Contents

- [Features](#features)
- [Requirements](#requirements)
- [Usage](#usage)
    - [`Enum`](#id2)
        - [Defining an enum class](#defining-an-enum-class)
            - [Custom key-value source](#custom-key-value-source)
        - [Supported value types](#supported-value-types)
        - [Method overview](#method-overview)
            - [Checking keys and values](#checking-keys-and-values)
            - [Ensuring existence of keys and values](#ensuring-existence-of-keys-and-values)
            - [Getting keys for values or values for keys](#getting-keys-for-values-or-values-for-keys)
            - [Getting key/value lists and maps](#getting-key-value-lists-and-maps)
            - [Getting pairs](#getting-pairs)
            - [Counting members](#counting-members)
    - [`EnumObject`](#id3)
        - [Defining an enum object class](#defining-an-enum-object-class)
        - [Creating instances](#creating-instances)
            - [Using a value](#using-a-value)
            - [Using a key](#using-a-key)
            - [Using the magic static factory method](#using-the-magic-static-factory-method)
            - [Getting all instances](#getting-all-instances)
        - [Method overview](#id4)
            - [Getting the key and value](#getting-the-key-and-value)
            - [Getting the pair](#getting-the-pair)
            - [Comparing the key and value](#comparing-the-key-and-value)
            - [String conversion](#string-conversion)
    - [Error handling](#error-handling)
    - [Value type coercion](#value-type-coercion)
        - [Examples](#examples)

[Features](#id5)
----------------

[](#features)

- immutability
- ensured unique keys and values
- simple to use (just extend a class and define some class constants)
- many methods related to keys
- values and their enumeration, maps and checking
- enum instances
- detailed exception messages

[Requirements](#id6)
--------------------

[](#requirements)

- PHP 7.1+

[Usage](#id7)
-------------

[](#usage)

### [`Enum`](#id8)

[](#enum-1)

The static `Enum` class provides access to the defined key-value pairs.

#### [Defining an enum class](#id9)

[](#defining-an-enum-class)

```
