0.1.1 2018-11-06 23:40 UTC


PHP version Latest Version License

Build Status Style Check Code Quality Code Coverage

Total Downloads Monthly Downloads


Immutable Enum objects for PHP

Other languages have the concept of Enum and while there is an extension in PHP for enums it's not so widely spread

The implementation of an Enum class is not so difficult, but it should cover value validation and be immutable so its value cannot be changed



composer require phpgears/enum


Require composer autoload file

require './vendor/autoload.php';

By extending Gears\Enum\AbstractEnum you can easily have an Enum class

use Gears\Enum\AbstractEnum;

class DatePeriodEnum extends AbstractEnum
    public const DAILY = 'daily';
    public const WEEKLY = 'weekly';
    public const BIWEEKLY = 'biweekly';
    public const MONTHLY = 'monthly';
    public const YEARLY = 'yearly';

$period = new DatePeriodEnum('daily');

$period->isEqualTo(new DatePeriodEnum(DatePeriodEnum::DAILY)); // true
$period->isEqualTo(new DatePeriodEnum(DatePeriodEnum::MONTHLY)); // false

$period->getValue(); // daily


Found a bug or have a feature request? Please open a new issue. Have a look at existing issues before.

See file


See file LICENSE included with the source code for a copy of the license terms.