oihana/php-enums

A collection of strongly-typed constant enumerations for PHP

1.0.0 2025-08-13 14:11 UTC

This package is auto-updated.

Last update: 2025-08-15 09:18:53 UTC


README

A collection of strongly-typed constant enumerations for PHP.

Latest Version
Total Downloads
License

Oihana PHP Enums is a lightweight PHP library providing a set of well-structured enumerations implemented as constant classes. Each enumeration groups related symbolic values to replace hardcoded strings or numbers, improving readability, consistency, and typo safety across your codebase.

This package is designed to be framework-agnostic, fully compatible with PHP 8.4+, and works seamlessly with the ConstantsTrait for reflection and dynamic constant access.

📚 Documentation

Full documentation: https://bcommebois.github.io/oihana-php-enums

📦 Installation

Requires PHP 8.4+. Install via Composer:

composer require oihana/php-enums

✨ What you can do

  • 📦 Multiple enumerations for different domains (e.g. Boolean, Char, IniOptions, and more).
  • 🔍 Reflection-ready with ConstantsTrait for listing or validating values.
  • 🛡️ Reduces “magic strings” and improves semantic clarity.
  • 🧩 Easily reusable in any PHP application or framework.
  • ⚡ No external dependencies except Oihana’s reflection utilities.

🚀 Quick Start

use oihana\enums\Boolean;
use oihana\enums\Char;
use oihana\enums\IniOptions;

// Boolean values as strings
$enabled = Boolean::TRUE; // 'true'

// Character constants
echo 'A' . Char::DOT . 'B'; // Outputs: A.B

// Ini options
ini_set(IniOptions::DISPLAY_ERRORS, '1');

✅ Running Unit Tests

To run all tests:

$ composer test

To run a specific test file:

$ composer test tests/oihana/enums/BooleanTest.php

🧾 License

This project is licensed under the Mozilla Public License 2.0 (MPL-2.0).

👤 About the author

🔗 Related packages

  • oihana/php-core – core helpers and utilities used by this library: https://github.com/BcommeBois/oihana-php-core
  • oihana/php-reflect – reflection and hydration utilities: https://github.com/BcommeBois/oihana-php-reflect