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

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

laudis/typed-enum
=================

A small class allowing for typed enumerations.

1.3.2(4y ago)4606.5k—2.4%4MITPHPPHP ^7.4 || ^8.0

Since Aug 27Pushed 4y ago1 watchersCompare

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

READMEChangelogDependencies (4)Versions (11)Used By (4)

Typed Enumerations
==================

[](#typed-enumerations)

Typed-enum is A simple, lightweight and efficient enumeration library. Type hint your enumerated options efficiently and strictly to eliminate unintended side effects and bugs introduced by typos.

How to use:
-----------

[](#how-to-use)

### Download

[](#download)

Download with composer:

### Extending from TypedEnum

[](#extending-from-typedenum)

Extend from TypedEnum and use any scalar constants to define the enumeration:

```
final class Foo extends TypedEnum {
    private const BAR = 'bar';
    private const BAZ = 2;
    private const FOO = 2.1;
}
```

You can now create instances of Foo by using the \_\_callstatic method based on the name of the constant:

```
Foo::BAR();  // Returns an instance of Foo with value 'bar'
```

### Testing for equality

[](#testing-for-equality)

As a bonus, you can now use strict comparisons. TypedEnum guarantees there to be only one instance of the same enumerated value at runtime.

```
function isBar(Foo $enum): bool {
    return Foo::BAR() === $enum;
}
```

### Return the actual value:

[](#return-the-actual-value)

If your application depends on the value assigned to the enumeration, you can easily fetch it with the getValue() getter.

```
echo Foo::BAR()->getValue(); //'bar'
```

### Resolve the enumeration

[](#resolve-the-enumeration)

Resolve an enumeration based on its value. The resolve method will return all enumerations with the same value in the array.

```
echo Foo::resolve('bar')[0] === Foo::BAR() // true
```

Tips
----

[](#tips)

### IDE integration

[](#ide-integration)

You can easily use the power of you ide by simply adding @method tags in the docblock of your class like this:

```
/**
 * @method static TypedEnum TEST()
 */
final class Foo extends TypedEnum {
    private const TEST = 'test';
}
```

### Psalm

[](#psalm)

We built TypedEnum with psalm! With these powerful annotations, you can now hint the scalar value of the enumeration:

```
/**
 * @extends TypedEnum
 */
final class Foo extends TypedEnum {
    private const TEST = 'test';
}
```

### Easy Bug protection

[](#easy-bug-protection)

Php 7.2 allows for protected constants, and 7.4 uses private ones. Use these features to protect against unintended side effects!

```
echo Foo::BAR === Foo::BAR() // echo's false but is impossible if it is a protected constant

```

---

Developed by [laudis](https://laudis.tech)

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 78.3% 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 ~136 days

Recently: every ~117 days

Total

10

Last Release

1595d ago

PHP version history (3 changes)v1.0.0PHP &gt;7.2.0

v1.1.0PHP &gt;=7.4

v1.2.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9cb8ab20866bd4fb9928742bc2321fcfe89d5e8560d4abfdd52ba139072b487b?d=identicon)[transitive](/maintainers/transitive)

---

Top Contributors

[![transistive](https://avatars.githubusercontent.com/u/16435930?v=4)](https://github.com/transistive "transistive (18 commits)")[![ghlen](https://avatars.githubusercontent.com/u/38523527?v=4)](https://github.com/ghlen "ghlen (5 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/laudis-typed-enum/health.svg)

```
[![Health](https://phpackages.com/badges/laudis-typed-enum/health.svg)](https://phpackages.com/packages/laudis-typed-enum)
```

###  Alternatives

[qandidate/toggle

Feature toggling for your PHP application.

3812.0M9](/packages/qandidate-toggle)[icehouse-ventures/laravel-chartjs

Simple package to facilitate and automate the use of charts in Laravel using the Chart.js library

117186.4k](/packages/icehouse-ventures-laravel-chartjs)

PHPackages © 2026

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