Download the PHP package php-compatible/enum without Composer

On this page you can find all versions of the php package php-compatible/enum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package enum

Enum

CI codecov License: MIT

PHP 7.2 PHP 7.3 PHP 7.4 PHP 8.0 PHP 8.1 PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5

PHP 8-style enums for PHP 7.2+ - Write enums today, upgrade to native enums tomorrow.

This library provides a PHP 8-compatible enum API that works on PHP 7.2 and above. When you're ready to upgrade to PHP 8.1+, use the included migration tool to automatically convert your enums to native PHP syntax.

Why Use This Package?

CLI Tools Included

Command Description
vendor/bin/php-compatible-enum-auto-doc Auto-generate @method PHPDoc annotations for IDE support
vendor/bin/php-compatible-enum-upgrade-to-php8 Migrate enums to native PHP 8.1+ syntax

Installation

Documentation

Full documentation available at phpcompatible.dev/docs/category/enum

Usage

Basic Enum (Auto-increment)

Define enum cases as protected properties. Uninitialized properties auto-increment from 0:

Mixed Values

Combine auto-increment with explicit values:

String Enum

Case-Insensitive Access

Access enum cases using any naming convention:

Getting All Cases

Looking Up by Value

Use from() and tryFrom() to get an enum case from its backing value (PHP 8 compatible):

Duplicate backing values are not allowed (matches PHP 8 behavior):

Human-Readable Labels

Use EnumLabel to convert enum names to human-readable labels:

EnumLabel handles various naming conventions:

Input Output
camelCase Camel Case
PascalCase Pascal Case
snake_case Snake Case
SCREAMING_SNAKE Screaming Snake
ABCValue ABC Value

Labels auto-convert to strings:

IDE Support

Add PHPDoc @method annotations for autocompletion:

Auto-generating Annotations

Use the php-compatible-enum-auto-doc CLI tool to automatically generate @method annotations:

The tool scans PHP files for classes that use PhpCompatible\Enum\Enum, extracts protected properties, and updates the class docblock with appropriate @method annotations. Files are listed as they are updated.

Upgrading to PHP 8 Native Enums

When you're ready to migrate to PHP 8.1+ native enums, use the php-compatible-enum-upgrade-to-php8 CLI tool:

The tool will:

  1. Convert enum class definitions - Transform class Status extends Enum to enum Status
  2. Update case declarations - Convert protected $draft; to case draft;
  3. Handle backed enums - Preserve integer or string backing values
  4. Update usages - Replace Status::draft() with Status::draft (removes parentheses)
  5. Swap EnumLabel - Replace EnumLabel::from() with Php8EnumLabel::from()

Before:

After:

How It Works

API Reference

Enum

Method Returns Description
CaseName() Value Get enum case (case-insensitive)
cases() Value[] Get all enum cases
from($value) Value Get case by value (throws if not found)
tryFrom($value) Value\|null Get case by value (null if not found)

Value

Property Type Description
$name string The enum case name (original definition)
$value int\|string\|null The enum case value

EnumLabel

Method Returns Description
from(Value $value) EnumLabel Create label from enum value
toString() string Get label as string
__toString() string Auto string conversion

Php8EnumLabel

For PHP 8.1+ native enums (extends EnumLabel):

Method Returns Description
fromEnum(UnitEnum $case) Php8EnumLabel Create label from PHP 8 enum case
toString() string Get label as string
__toString() string Auto string conversion

Requirements

License

MIT


All versions of enum with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
symfony/console Version ^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package php-compatible/enum contains the following files

Loading the files please wait ...