oihana / php-enums
A collection of strongly-typed constant enumerations for PHP
Requires
- php: >=8.4
- oihana/php-core: dev-main
- oihana/php-reflect: dev-main
Requires (Dev)
- mikey179/vfsstream: ^1.6
- nunomaduro/collision: ^8.8
- phpdocumentor/shim: ^3.8
- phpunit/phpunit: ^12
README
A collection of strongly-typed constant enumerations for PHP.
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
- Author : Marc ALCARAZ (aka eKameleon)
- Mail : marc@ooop.fr
- Website : http://www.ooop.fr
🔗 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