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

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

brzez/php-magic-enum
====================

v0.9.8(10y ago)024MIT

Since Jun 19Compare

[ Source](https://github.com/brzez/php-magic-enum)[ Packagist](https://packagist.org/packages/brzez/php-magic-enum)[ RSS](/packages/brzez-php-magic-enum/feed)WikiDiscussions Synced yesterday

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

php-magic-enum
==============

[](#php-magic-enum)

Easy to use &amp; extend enum value objects for php

Overview
--------

[](#overview)

PHP lacks enums. Everyone usually just uses const values, which don't really provide type safety, and can create messy code.

This might be a solution to this problem. It provides a enum value object.

This magic enum can be instanced via magic methods (named the same as consts) which create new instances of the enum with value set to the consts value.

Example enum:

```
class OrderStatus extends \MagicEnum\MagicEnum
{
	const CREATED        = 1;
	const COMPLETE       = 2;
	const CANCELLED      = 3;
	const PROCESSING     = 4;

	// easy way to extend with the status (for labels/translations etc)
	public function getLabel()
	{
		$name = strtolower($this->getName());
		return "order_status.${name}";
	}
}
```

Usage:

```
// create new instance:
$status = OrderStatus::PROCESSING();
$status->getValue() // => 4

// type safety
public function setStatus(OrderStatus $status)
{
  $this->status = $status;
}
// safe setter (but less annoying)
public function setStatus($status)
{
  if($status instanceof OrderStatus){
    $this->status = $status;
  }else{
    $this->status = new OrderStatus($status); // this validates if $status is defined in OrderStatus const values
  }
}
```

Extras:

```
{# it's easy to extend the enums with some additional features for example: #}
{{ order.status.label|trans }}
```

todo:
-----

[](#todo)

- Add to packagist
- Write help for installation via composer
- Write some more usage help

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

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

Unknown

Total

1

Last Release

3663d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1938838?v=4)[Paweł Brzeziński](/maintainers/brzez)[@brzez](https://github.com/brzez)

---

Top Contributors

[![brzez](https://avatars.githubusercontent.com/u/1938838?v=4)](https://github.com/brzez "brzez (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/brzez-php-magic-enum/health.svg)

```
[![Health](https://phpackages.com/badges/brzez-php-magic-enum/health.svg)](https://phpackages.com/packages/brzez-php-magic-enum)
```

###  Alternatives

[josespinal/filament-record-navigation

Record navigation from views

3145.4k2](/packages/josespinal-filament-record-navigation)

PHPackages © 2026

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