PHPackages                             erikaraujo/php-enhanced-enums - 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. erikaraujo/php-enhanced-enums

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

erikaraujo/php-enhanced-enums
=============================

Enhanced enum methods for PHP enums

2.0.0(1y ago)113.6k↓50%MITPHPPHP ^8.1

Since May 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/erikaraujo/php-enhanced-enums)[ Packagist](https://packagist.org/packages/erikaraujo/php-enhanced-enums)[ RSS](/packages/erikaraujo-php-enhanced-enums/feed)WikiDiscussions 2.0 Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (6)Used By (0)

PHP Enhanced Enums
==================

[](#php-enhanced-enums)

Enhanced Enum methods for PHP Enums

In this package, we have 4 traits: `EnhancedEnum`, `HasDescription`, `HasLabel` and `IsSelectArray`. Here are all the methods that each trait provides:

- [EnhancedEnum](#enhancedenum)

    - [`parse()`](#parse)
    - [`tryParse()`](#tryparse)
    - [`tryFromIgnoringCase()`](#tryfromignoringcase)
    - [`tryParseIgnoringCase()`](#tryparseignoringcase)
    - [`getNames()`](#getnames)
    - [`getValues()`](#getvalues)
    - [`isDefined()`](#isdefined)
    - [`toString()`](#tostring)
    - [`is()`](#is)
    - [`getBackingType()`](#getbackingtype)
    - [`getUnderlyingType()`](#getunderlyingtype)
    - [`isIntEnum()`](#isintenum)
    - [`isStringEnum()`](#isstringenum)
    - [`getRandom()`](#getrandom)
    - [`getCaseByPosition()`](#getcasebyposition)
    - [`tryGetCaseByPosition()`](#trygetcasebyposition)
    - [`first()`](#first)
    - [`last()`](#last)
- [HasDescription](#hasdescription)

    - [`getDescription()`](#getdescription)
    - [`getDescriptions()`](#getdescriptions)
    - [`tryFromDescription()`](#tryfromdescription)
    - [`tryFromDescriptionIgnoringCase()`](#tryfromdescriptionignoringcase)
- [HasLabel](#haslabel)

    - [`getLabel()`](#getlabel)
    - [`getLabels()`](#getlabels)
    - [`tryFromLabel()`](#tryfromlabel)
    - [`tryFromLabelIgnoringCase()`](#tryfromlabelignoringcase)
    - [`shouldAutoGenerateLabelFromValue()`](#shouldautogeneratelabelfromvalue)
- [IsSelectArray](#isselectarray)

    - [`asSelectArray()`](#asselectarray)

EnhancedEnum
------------

[](#enhancedenum)

### `parse()`

[](#parse)

This method is simply an alias to the native `from()` method. Here's an example:

```
Suit::parse('hearts'); // Returns the Suit::Hearts case

Suit::parse('invalid'); // Throws an exception
```

### `tryParse()`

[](#tryparse)

This method is an improved alias to the `tryFrom()` method. The difference here, is that, instead of only having the `$value` parameter, it also has a `$ignoreCase` boolean parameter to allow the method to ignore the case of the value before parsing it. Here's an example:

```
Suit::tryParse('hearts'); // Returns the Suit::Hearts case

Suit::tryParse('invalid'); // Returns null

Suit::tryParse('hEaRtS'); // Returns null

Suit::tryParse('hEaRtS', ignoreCase: true); // Returns the Suit::Hearts case
```

### `tryFromIgnoringCase()`

[](#tryfromignoringcase)

// TODO

### `tryParseIgnoringCase()`

[](#tryparseignoringcase)

An alias to `tryFromIgnoreCase()`.

### `getNames()`

[](#getnames)

This method returns an array with all the names of the enum cases. Here's an example:

```
Suit::getNames(); // Returns ['Hearts', 'Diamonds', 'Clubs', 'Spades']
```

### `getValues()`

[](#getvalues)

This method returns an array with all the values of the enum cases. Here's an example:

```
Suit::getValues(); // Returns ['hearts', 'diamonds', 'clubs', 'spades']
```

### `isDefined()`

[](#isdefined)

This method checks if a given value is defined in the enum. Here's an example:

```
Suit::isDefined('hearts'); // Returns true

Suit::isDefined('invalid'); // Returns false

Suit::isDefined('hEaRtS'); // Returns false

Suit::isDefined('hEaRtS', ignoreCase: true); // Returns true
```

### `toString()`

[](#tostring)

This method returns the value of the enum as string - even if it's an integer enum.

### `is()`

[](#is)

TODO: describe

```
Suit::Hearts->is(Suit::Spades); // Returns `false`
Suit::Hearts->is('spades'); // Returns `false`

Suit::Hearts->is(Suit::Hearts); // Returns `true`
Suit::Hearts->is('hearts'); // Returns `true`
Suit::Hearts->is('HeArTs'); // Returns `false`
Suit::Hearts->is('HeArTs', ignoreCase: true); // Returns `true`
```

### `getBackingType()`

[](#getbackingtype)

// TODO: describe

```
Suits::getBackingType(); // returns the `ReflectionNamedType`. In this case, with `string` as a `name`.
```

### `getUnderlyingType()`

[](#getunderlyingtype)

An alias to `getBackingType()`

### `isIntEnum()`

[](#isintenum)

Returns if the enum's backing type is an integer.

```
Suit::isIntEnum(); // Returns false
```

### `isStringEnum()`

[](#isstringenum)

Returns if the enum's backing type is a string.

```
Suit::isStringEnum(); // Returns true
```

### `getRandom()`

[](#getrandom)

Returns a random enum case.

### `getCaseByPosition()`

[](#getcasebyposition)

```
```

### `tryGetCaseByPosition()`

[](#trygetcasebyposition)

```
```

### `first()`

[](#first)

```
```

### `last()`

[](#last)

```
```

HasDescription
--------------

[](#hasdescription)

### `getDescription()`

[](#getdescription)

Returns the description of the given enum

```
Suit::Hearts->getDescription(); // Returns "The suit of hearts"
```

### `getDescriptions()`

[](#getdescriptions)

Returns an array of all the descriptions

```
Suit::getDescriptions();
```

### `tryFromDescription()`

[](#tryfromdescription)

```
```

### `tryFromDescriptionIgnoringCase()`

[](#tryfromdescriptionignoringcase)

```
```

HasLabel
--------

[](#haslabel)

### `getLabel()`

[](#getlabel)

```
```

### `getLabels()`

[](#getlabels)

```
```

### `tryFromLabel()`

[](#tryfromlabel)

```
```

### `tryFromLabelIgnoringCase()`

[](#tryfromlabelignoringcase)

```
```

### `shouldAutoGenerateLabelFromValue()`

[](#shouldautogeneratelabelfromvalue)

`protected`

```
```

IsSelectArray
-------------

[](#isselectarray)

### `asSelectArray()`

[](#asselectarray)

```
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance40

Moderate activity, may be stable

Popularity24

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

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

Total

5

Last Release

601d ago

Major Versions

1.0.x-dev → 2.0.02024-09-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/aa723c47683204ef4b5d64e54a5ed421533b72a910a9e17d80341f3c88afdea1?d=identicon)[erikaraujo](/maintainers/erikaraujo)

---

Top Contributors

[![erikaraujo](https://avatars.githubusercontent.com/u/16599401?v=4)](https://github.com/erikaraujo "erikaraujo (10 commits)")

---

Tags

phpenumEnhanced

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/erikaraujo-php-enhanced-enums/health.svg)

```
[![Health](https://phpackages.com/badges/erikaraujo-php-enhanced-enums/health.svg)](https://phpackages.com/packages/erikaraujo-php-enhanced-enums)
```

###  Alternatives

[kongulov/interact-with-enum

Trait for convenient use of ENUM in PHP

3052.3k2](/packages/kongulov-interact-with-enum)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)[vjik/php-enum

PHP Enum Implementation

209.9k](/packages/vjik-php-enum)[ducks-project/spl-types

Polyfill Module for SplType PHP extension. This extension aims at helping people making PHP a stronger typed language and can be a good alternative to scalar type hinting. It provides different typehandling classes as such as integer, float, bool, enum and string

1032.4k](/packages/ducks-project-spl-types)

PHPackages © 2026

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