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

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

vosiz/php-enum
==============

PHP simple enum-like class

v2.3.0(8mo ago)0541MITPHPPHP &gt;=7.4

Since Jan 26Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/vosiz/php-enum)[ Packagist](https://packagist.org/packages/vosiz/php-enum)[ RSS](/packages/vosiz-php-enum/feed)WikiDiscussions main Synced today

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

PHP Enum(erations)
==================

[](#php-enumerations)

Utility to have enum-like classes. We love ENUMS! True enumeration with integers seems to be impossible to achieve (at least for me). Designed to be dynamical (not only for compile time - read values from DB f.e. and make dynamic enums)

Bug report
----------

[](#bug-report)

None taken

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

[](#installation)

### Composer

[](#composer)

Install with

```
composer install vosiz/php-enum

```

Update with (dependencies/required)

```
composer update

```

Usage
-----

[](#usage)

Implement your own enums! Lets say, you have a game and want elemental magic defined other way than with defines or constants. You want to do something like this:

```
use Vosiz\Enums\Enum;

class Elements extends Enum {

    public static function Init(): void {

        $vals = [
            'Fire' => 0,
            'Water' => 1,
            'Air' => 2,
            'Earth' => 3,
        ];
        self::AddValues($vals);
    }
}
```

Important

You can multiple same values allocated to diferent keys (as some classic enum does not allow it) - here it is permitted. But you can lose consistency if you base on integers (values) too much.

### Usage sample - int-like

[](#usage-sample---int-like)

Now you can simply use it for example like this. It is value based - integers.

```
$elements = Elements::GetValues(); // all enum values - foreach usage f.e.

$armor->ResistanceType = Elements::GetEnumVal('Fire'); // allocate enum variable

if($armor->ResistanceType == Elements::GetEnumVal('Water');) { // comparation

    ...
}
```

### Usage sample - enum-like

[](#usage-sample---enum-like)

If you need to track or operate with naming of enum (enum key and value in general), you should use something like this:

```
$enum = Elements::GetEnum('Earth');

// access key or value
$key = $enum->GetKey(); // alt GetName()
$val = $enum->GetValue();

// compare
$is_water = $enum->Compare(Elements::GetEnum('Water'));

// i fyou know value but not name
$what_is_the_key = Elements::Find('Air');
```

### Useful tips

[](#useful-tips)

If you want to distinct 'key' from 'sho key', there is Display property. It is automatically set to key, but you can set it up in custom enum definition. Example.

```
class EdibleEnum extends Enum {

    public static function Init(): void {

        $vals = [
            'apple'     => 0,
            'leek'      => [100, 'pure poison'],
            'peach'     => 69,
            'pear'      => [1, 'apple relative'],

        ];
        self::AddValues($vals);
    }
}
```

Important

You have to still keep first value of array as int (core functionality of enum).

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance59

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity44

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

Recently: every ~56 days

Total

6

Last Release

261d ago

Major Versions

v1.0.1 → v2.0.02025-03-01

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/12089682?v=4)[Petr "Vošiz" Vošoust](/maintainers/vosiz)[@vosiz](https://github.com/vosiz)

---

Top Contributors

[![vosiz](https://avatars.githubusercontent.com/u/12089682?v=4)](https://github.com/vosiz "vosiz (16 commits)")

### Embed Badge

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

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

###  Alternatives

[consoletvs/charts

The laravel charting package

1043.8M29](/packages/consoletvs-charts)[joetannenbaum/chewie

122561.2k22](/packages/joetannenbaum-chewie)[google/appengine-php-sdk

Google App Engine PHP SDK

29803.0k4](/packages/google-appengine-php-sdk)[semperfiwebdesign/all-in-one-seo-pack

All in One SEO Pack plugin for WordPress SEO

3652.1k](/packages/semperfiwebdesign-all-in-one-seo-pack)[infyomlabs/laravel-calendar-events

Recurring Calendar Events for Laravel

998.6k](/packages/infyomlabs-laravel-calendar-events)

PHPackages © 2026

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