PHPackages                             josezenem/php-enums-extended - 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. josezenem/php-enums-extended

ActiveLibrary

josezenem/php-enums-extended
============================

PHP 8.1 Enums Extended adds additional functionality when working with PHP 8.1+ Enums.

3.1.0(4y ago)563.0k—4%1[2 PRs](https://github.com/josezenem/php-enums-extended/pulls)MITPHPPHP ^8.1CI passing

Since Feb 2Pushed 4mo ago2 watchersCompare

[ Source](https://github.com/josezenem/php-enums-extended)[ Packagist](https://packagist.org/packages/josezenem/php-enums-extended)[ Docs](https://github.com/josezenem/php-enums-extended)[ GitHub Sponsors](https://github.com/josezenem)[ RSS](/packages/josezenem-php-enums-extended/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (2)Versions (11)Used By (0)

PHP 8.1 Enums Extended
======================

[](#php-81-enums-extended)

[![Latest Stable Version](https://camo.githubusercontent.com/ae76abf898c766c81b72ceb2d959136d9e1594ce089ff624413bb402fb923396/687474703a2f2f706f7365722e707567782e6f72672f6a6f73657a656e656d2f7068702d656e756d732d657874656e6465642f76)](https://packagist.org/packages/josezenem/php-enums-extended)[![Tests](https://github.com/josezenem/php-enums-extended/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/josezenem/php-enums-extended/actions/workflows/run-tests.yml)[![Codacy Badge](https://camo.githubusercontent.com/d0b7747e4cb3e08e7ec29befbeafafc33ea8e3b152637de411a4d7cf41300951/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3062643233393937343766303435653738303339653732643531613837333535)](https://www.codacy.com/gh/josezenem/php-enums-extended/dashboard?utm_source=github.com&utm_medium=referral&utm_content=josezenem/php-enums-extended&utm_campaign=Badge_Grade)[![Total Downloads](https://camo.githubusercontent.com/0161b43928cea933ebd320ea680db71f338c050591436852a8ff441f5b99a5a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f73657a656e656d2f7068702d656e756d732d657874656e6465642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/josezenem/php-enums-extended)[![PHP Version Require](https://camo.githubusercontent.com/2edec5de5b82f233795ea4ca586f27cc1a41939e5968003aec5bae48202cb891/687474703a2f2f706f7365722e707567782e6f72672f6a6f73657a656e656d2f7068702d656e756d732d657874656e6465642f726571756972652f706870)](https://packagist.org/packages/josezenem/php-enums-extended)

PHP 8.1 Enums Extended, gives you the ability to use additional methods to work with PHP 8.1 Enums.

```
enum StatusEnum:int
{
    case Closed = 0;
    case Open = 1;
    case PENDING_APPROVAL = 2;
}

// Given a new Blog() that uses the enum trait, you can do things like:
$blog->status->isOpen() // Will return boolean
$blog->status->equals(StatusEnum::Open, StatusEnum::Closed)

// Normalization happens in the background allowing these scenarios
$blog->status->isPendingApproval();
$blog->status->isPENDING_APPROVAL();

StatusEnum::Open() // Will return ->value, vs doing StatusEnum::Open->value
StatusEnum::PendingApproval()
StatusEnum::PENDING_APPROVAL()
```

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

[](#installation)

You can install the package via composer:

```
composer require josezenem/php-enums-extended
```

Usage
-----

[](#usage)

[`Available Methods`](#available-methods)
-----------------------------------------

[](#available-methods)

- [`equals()`](#method-equals)
- [`doesNotEqual()`](#method-does-not-equal)
- [`isCall**()`](#method-is-call)

[`Available Static Methods`](#available-static-methods)
-------------------------------------------------------

[](#available-static-methods)

- [`options()`](#static-method-to-options-array)
- [`optionsFlipped()`](#static-method-to-options-flipped-array)
- [`names()`](#static-method-to-names-array)
- [`hasName()`](#static-method-has-name)
- [`values()`](#static-method-to-values-array)
- [`hasValue()`](#static-method-has-value)
- [`call**()`](#static-method-call)

### `equals()`

[](#equals)

Pass one or multiple Enum cases, will return boolean if one matches.

```
$blog->status->equals(StatusEnum::Closed, StatusEnum::Draft);
```

### `doesNotEqual()`

[](#doesnotequal)

Pass one or multiple Enum cases, will return boolean if it does not match.

```
$blog->status->doesNotEqual(StatusEnum::Closed, StatusEnum::Draft);
```

### `isCall**()`

[](#iscall)

Returns boolean if the current value matches the desired case. Methods with underscores can be accessed via camel case, as well as their regular name.

```
$blog->status->isDraft();

// Given StatusEnum::OPEN_ISSUE = 4;
// the following is acceptable.
$blog->status->isOpenIssue();
$blog->status->isOPEN_ISSUE();
```

### `options()`

[](#options)

Will return an array of $val =&gt; $key.

```
$options = self::options()

// returns
$options = [
    'open' => 'Open',
    'closed' => 'Closed',
    'draft' => 'Draft',
]
```

### `optionsFlipped()`

[](#optionsflipped)

Will return an array of $key =&gt; $val.

```
$options = self::optionsFlipped()

// returns
$options = [
    'Open' => 'open',
    'Closed' => 'closed',
    'Draft' => 'draft',
]
```

### `names()`

[](#names)

Will return an array of only names

```
$options = self::names()

// returns
$options = [
    'Open' => 'Open',
    'Closed' => 'Closed',
    'Draft' => 'Draft',
]
```

### `hasName()`

[](#hasname)

Pass variable and confirm if the name is valid for the Enum

```
App\MyEnums\Type::hasName('Closed');
// Returns true

App\MyEnums\Type::hasName('close');
// Returns false
```

### `values()`

[](#values)

Will return an array of only values

```
$options = self::values()

// returns
$options = [
    'open' => 'open',
    'closed' => 'closed',
    'draft' => 'draft',
]
```

### `hasValue()`

[](#hasvalue)

Pass variable and confirm if the value is valid for the Enum

```
App\MyEnums\Type::hasValue('closed');
// Returns true

App\MyEnums\Type::hasValue('not a valid value for the enum');
// Returns false
```

### `call**()`

[](#call)

Will allow you to grab the value of a field by calling it statically.

```
// Consider the following scenario, to get the value you would do:
// StatusEnum::Open->value
enum StatusEnum:int
{
    case Closed = 0;
    case Open = 1;
    case Draft = 2;
}

// You can instead get value directy by calling it statically
// Case Insensitive
StatusEnum::OPEN()
StatusEnum::Open()
```

### Exception Handler

[](#exception-handler)

When using the magic methods, if the method calls do not exist, the system will throw

```
Josezenem\PhpEnumsExtended\Exceptions\EnumsExtendedException

```

```
// StatusEnum.php
// StatusEnum:int is used for the example, but supports :string and default of just StatusEnum
use Josezenem\PhpEnumsExtended\Traits\PhpEnumsExtendedTrait;

enum StatusEnum:int
{
    use PhpEnumsExtendedTrait;

    case Closed = 0;
    case Open = 1;
    case Draft = 2;
}

// Blog.php
class Blog
{
    public function __construct(
        public StatusEnum $status = StatusEnum::Open,
    ) {
    }
}

// Usage
$blog = new Blog();

// ->equals()
$blog->status->equals(StatusEnum::Open); // will return true if it matches
$blog->status->equals(StatusEnum::Closed, StatusEnum::Open); // Pass any number of params, will return true if it matches any of the parameters

// ->doesNotEqual()
$blog->status->doesNotEqual(StatusEnum::Closed); // will return true if it does not match
$blog->status->doesNotEqual(StatusEnum::Closed, StatusEnum::Draft)  // Pass any number of params, will return true if it does not match any of the parameters

// ->is** magic method
// the magic method takes camelCase allowing you to do boolean check against any field.
$blog->status->isOpen() // will return true or false

// ::options()
$options = StatusEnum::options();

// will output
//$options = [
//    0 => 'Closed',
//    1 => 'Open',
//    2 => 'Closed',
//];

// ::optionsFlipped()
$options = StatusEnum::optionsFlipped();

// will output
//$options = [
//    'Closed' => 0,
//    'Open' => 1,
//    'Closed' => 2,
//];
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Jose Jimenez](https://github.com/josezenem)
- [All Contributors](../../contributors)
- Special Thanks to [Shocm](https://twitter.com/shocm) for pushing me to make this, and answering my late replies.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance52

Moderate activity, may be stable

Popularity36

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Total

9

Last Release

1522d ago

Major Versions

1.x-dev → 2.0.02022-02-24

2.x-dev → 3.0.02022-02-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/199e41d6a1dd8442051e8a54b24af15f894d09a016cc9e80f2fb004ed7530345?d=identicon)[josezenem](/maintainers/josezenem)

---

Top Contributors

[![josezenem](https://avatars.githubusercontent.com/u/377520?v=4)](https://github.com/josezenem "josezenem (38 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (21 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (15 commits)")[![ericvanjohnson](https://avatars.githubusercontent.com/u/89408?v=4)](https://github.com/ericvanjohnson "ericvanjohnson (5 commits)")[![SerhiiKorniienko](https://avatars.githubusercontent.com/u/95961352?v=4)](https://github.com/SerhiiKorniienko "SerhiiKorniienko (1 commits)")

---

Tags

enumslaravelphpenumsjosezenemphp-enums-extended

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/josezenem-php-enums-extended/health.svg)

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

###  Alternatives

[henzeb/enumhancer

Your framework-agnostic Swiss Army knife for PHP 8.1+ native enums

69287.4k2](/packages/henzeb-enumhancer)[josezenem/laravel-make-migration-pivot

Make Laravel pivot tables using the new Laravel 9 closure migrations.

2077.6k](/packages/josezenem-laravel-make-migration-pivot)[brysem/phpenums

Enums made simple in PHP.

10171.5k](/packages/brysem-phpenums)[josezenem/laravel-slugidable

A package for Laravel that creates slugs for Eloquent models based on title and ID

1159.5k](/packages/josezenem-laravel-slugidable)[defstudio/enum-features

A simple trait to enable a feature system using Enums and Laravel Pennant

162.1k](/packages/defstudio-enum-features)[sakanjo/laravel-easy-enum

Easily work with enum.

101.4k1](/packages/sakanjo-laravel-easy-enum)

PHPackages © 2026

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