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

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

githubjeka/enum
===============

Simple and base functional to start using Enum in your projects.

v2.0.0(6y ago)0241MITPHPPHP &gt;=7.1

Since Jul 17Pushed 6y ago1 watchersCompare

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

READMEChangelog (2)DependenciesVersions (3)Used By (0)

[![Build Status](https://camo.githubusercontent.com/5351c241c70844d2712b1179a7105ed0c9adfe2bd474fa3bd0f4e47a0db27d56/68747470733a2f2f7472617669732d63692e636f6d2f6769746875626a656b612f656e756d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/githubjeka/enum)

Usage ENUM
----------

[](#usage-enum)

Simple and base functional to start using Enum in your projects. Just initialize enum value by creating Enum class.

```
final class SizeEnum extends \githubjeka\enum\BaseObjectEnum
{
    const XS = 'xs';
    const SMALL = 's';
    const MEDIUM = 'm';
    const LARGE = 'l';
    const XL = 'xl';
    const XXL = 'xxl';

    public static function getList(): array
    {
        return [
            self::XS => 'Extra small(xs)',
            self::SMALL => 'Small',
            self::MEDIUM => 'Medium',
            self::LARGE => 'Large',
            self::XL => 'Extra large(xl)',
            self::XXL => 'Extra extra large(xxl)',
        ];
    }
}
```

After that you can use API enums as:

#### `SizeEnum::getList()`

[](#sizeenumgetlist)

Return ready list for use in HTML list elements like checkboxes, select or others

#### `SizeEnum::getKeys()`

[](#sizeenumgetkeys)

Return values of ENUM for use it in validation rules like `Assertion::inArray('xs', SizeEnum::getKeys());`;

#### `SizeEnum::XXL`

[](#sizeenumxxl)

Return string key. Use to compare with the saved values `(bool)('xxl' === SizeEnum::XXL)?>`;

#### `SizeEnum::getLabel(SizeEnum::LARGE)`

[](#sizeenumgetlabelsizeenumlarge)

Return human description of value. `InvalidArgumentException` will be returned if value is wrong.

#### `SizeEnum::isValid('xl')`

[](#sizeenumisvalidxl)

Use to avoid `InvalidArgumentException` exception.

#### `new SizeEnum('xxl')`

[](#new-sizeenumxxl)

Return Object enum.

```
class Shirt
{
    private $size;

    public function __construct(SizeEnum $size)
    {
        $this->size = $size;
    }

    public function size(): SizeEnum
    {
        return $this->size;
    }
}

$sizeFromDb = 'xxl';
$size = new SizeEnum($sizeFromDb);
$shirt = new Shirt($size);

$shirt->size()->asKey(); // (string) xxl

$shirt->size()->asLabel(); // (string) Extra extra large(xxl)

$shirt->size()->equals(new SizeEnum(SizeEnum::XS)); // (bool) false

echo $shirt->size(); // (string) xxl
```

Extra
-----

[](#extra)

Strongly recommend that you do not use numbers as enumeration values:

```
const XS = '0';         // not recommend
const SMALL = '1';      // not recommend
const MEDIUM = 2;       // not recommend
const LARGE = 3;        // not recommend
```

because it is easy to mix up the strings and the underlying number values if you quote the ENUM values incorrectly.

**By default expected that all Enum(constants) are Strings.**

If you want to use integers you can change `$stringMode` property to `FALSE` in your Enum class. After that should use only integers value for constants:

```
const XS = 0;
const SMALL = 1;
const MEDIUM = 2;
const LARGE = 3;
```

If you [use MySQL ENUM see limits also](https://dev.mysql.com/doc/refman/8.0/en/enum.html#enum-limits)

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

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

Total

2

Last Release

2301d ago

Major Versions

v1.0.0 → v2.0.02020-03-12

PHP version history (2 changes)v1.0.0PHP &gt;=7.0

v2.0.0PHP &gt;=7.1

### Community

Maintainers

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

---

Top Contributors

[![githubjeka](https://avatars.githubusercontent.com/u/874234?v=4)](https://github.com/githubjeka "githubjeka (11 commits)")

---

Tags

enumenum

### Embed Badge

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

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

###  Alternatives

[myclabs/php-enum

PHP Enum implementation

2.7k233.3M681](/packages/myclabs-php-enum)[dasprid/enum

PHP 7.1 enum implementation

382158.8M12](/packages/dasprid-enum)[spatie/enum

PHP Enums

84931.4M74](/packages/spatie-enum)[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

49753.5M104](/packages/marc-mabe-php-enum)[spatie/laravel-enum

Laravel Enum support

3655.7M34](/packages/spatie-laravel-enum)[consistence/consistence

Consistence - consistent approach and additions to PHP's functionality

1821.1M18](/packages/consistence-consistence)

PHPackages © 2026

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