Skip to content
This repository has been archived by the owner on Mar 18, 2021. It is now read-only.

vladdeSV/simple-enum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleEnum

SimpleEnum

dead simple minimum php version master

Dead simple PHP enum. This thing runs on PHP 5.3, heck maybe even PHP 5.1.2*, so just yoink the files if you need it for your Legacy project.

* This enum uses the Reflection class, which was introduced in PHP 5.1.2

Why?

I come from C-like languages with proper enums. Why is there no such simple, built-in, proper, enum in PHP?

The SplEnum looks promising, but has some oddities with its implementation. As an added bonus, it might not work for your setup.

Other third-party alternatives (see this, this, this, and this for instance) are overly complicated for my needs. This should probably solve it for most of my use cases.

Example

<?php

use SimpleEnum\Enum;

class MyEnum extends Enum
{
    const foo = 1;
    const bar = 2;
    const baz = 3;
}

$myEnum = new MyEnum(MyEnum::foo);

assert($myEnum->value() === MyEnum::foo);
assert($myEnum->equals(new MyEnum(1)));

Installation

composer require vladdesv/simple-enum

License

MIT © Vladimirs Nordholm