- What is greg0ire/enum and what problem does it solve?
- greg0ire/enum is a lightweight PHP library that emulates enum-like behavior before native PHP enum types existed. It lets you define classes with constants, validate values against those constants, and access the available constants. It is intended for legacy projects that need reusable sets of values without a heavy dependency.
- How do I install greg0ire/enum in a Laravel application?
- Install it as a normal Composer dependency with composer require greg0ire/enum. There is no Laravel service provider, facade, configuration file, or migration to publish. Adoption is a one-line require plus refactoring call sites to use its AbstractEnum base class and validation helpers.
- Does greg0ire/enum work with Laravel 9, 10, or 11?
- It is a plain Composer library with no framework coupling, so Composer may allow it on newer Laravel versions. However, it is not recommended for Laravel 9, 10, or 11 because those versions run on PHP 8.0 or 8.1 and native enum types supersede this package. Treat it strictly as a legacy compatibility shim for older Laravel applications.
- Which Laravel and PHP versions is greg0ire/enum actually suitable for?
- It fits only the narrow band of applications still running PHP 7.x or early PHP 8.0, typically Laravel 5.8 through 8.x. On any modern Laravel baseline with PHP 8.1 or newer, native backed enums and enum_exists supersede it entirely. Greenfield projects should mandate native enums instead of adopting this package.
- How do I define an enum class with greg0ire/enum?
- You extend the provided AbstractEnum base class and define class constants for the allowed values. The base class then provides validation and constant-discovery helpers around those constants. Check the README for the exact method names and usage patterns in your target version.
- How do I validate an enum value with greg0ire/enum?
- The package provides validation helpers that check a candidate value against the constants defined on your enum class. Because these are emulated enums, validation is not enforced by the language type system, so invalid values can still reach persistence layers or API boundaries if you skip the helper. Always validate at input boundaries and before saving to the database.
- Is greg0ire/enum safe to use in production?
- Only after legal and supply-chain review. The package has a reported license of NOASSERTION, so you must confirm licensing before shipping or vendoring it. It also appears to be in maintenance or legacy mode, with the last release in May 2023 and low adoption, so expect no fixes for future PHP deprecations. It is not appropriate for greenfield or modern Laravel services.
- What license does greg0ire/enum use, and why is NOASSERTION a concern?
- The package license is reported as NOASSERTION, meaning the license terms are not clearly declared or recognized. That is a legal ambiguity, not a runtime bug, but it can block redistribution, vendoring, or commercial use. Get legal confirmation before depending on it, and vendor or replace it if the upstream terms cannot be verified.
- How does greg0ire/enum compare to native PHP 8.1 enums?
- Native PHP 8.1 backed enums provide language-level type safety, built-in validation through from and tryFrom, and first-class serialization support. greg0ire/enum emulates enum semantics with class constants and helper methods, so invalid values are not stopped by the type system. Native enums are the better choice for any codebase on PHP 8.1 or newer.
- How do I migrate from greg0ire/enum to native PHP backed enums?
- Contain existing usages behind a thin internal interface or abstract base such as App\Support\Enum so call sites do not reference the third-party class directly. Then convert each service to native backed enums behind that same interface, using from or tryFrom for validation and mapping persisted scalar values through a serialization adapter. Remove the Composer dependency only after all services are on PHP 8.1 or newer, and keep one rollback-capable step between persistence changes and dependency deletion.