Home

Awesome

PHP enumeration libraries comparison

This project provides an unified feature comparison between most popular PHP enumeration (enum) libraries.

Libraries

Process

Each vendor implementation defines an equivalent of two enumerations:

final class FirstEnum
{
    public const VALID_A = 'valid-a';
    public const VALID_B = 'valid-b';

    public const PUBLIC_A = 'public-a';
    public const PUBLIC_B = 'public-b';
    protected const PROTECTED_A = 'protected-a';
    protected const PROTECTED_B = 'protected-b';
    private const PRIVATE_A = 'private-a';
    private const PRIVATE_B = 'private-b';
}

final class OtherEnum
{
    public const OTHER = 'other';
}

and an implementation of VendorInterface which provides all kinds of callbacks to verify the claims listed below. First two enum members (VALID_A, VALID_B) must be defined so that it's possible to create instances with these values, the rest must be provided as-is to verify other claims.

Features

Features are divided into groups, based on the common use cases. Feature "passes" if the library allows to complete certain requirement with a simple call to its methods - dedicated manipulation of the returned value in order to match the expectations is not allowed. All tests are listed below:

Ideas

Links