Smart Enum: Native enums that know isActive()
Add use SmartEnum; to any native PHP enum and every case can answer for itself: $status->isActive() for Active, $order->isInProgress() for IN_PROGRESS. You also get helpers for names, values, labels, options, lookup by case name and strict comparisons. Your enums stay native: no base class, no code generation, no framework.
Compatibility
Each line is released for the versions in its row, read from that release's composer.json. Pick the line that matches your project; a combination not listed isn't supported. Find the right line of every package for your project.
| Line | Latest release | PHP | Status | Docs |
|---|---|---|---|---|
| v8.5.x | v8.5.1 Oct 9, 2026 | 8.5 | Current | Docs: Read the v8.5.x docs |
| v8.4.x | v8.4.0 Oct 9, 2026 | 8.4 | Maintained | Docs: Read the v8.4.x docs |
| v8.3.x | v8.3.0 Oct 9, 2026 | 8.3 | Maintained | Docs: Read the v8.3.x docs |
| v8.2.x | v8.2.0 Oct 9, 2026 | 8.2 | Maintained | Docs: Read the v8.2.x docs |
| v8.1.x | v8.1.1 Oct 9, 2026 | 8.1 | MaintainedPHP 8.1 no longer gets security fixes | Docs: Read the v8.1.x docs |
Maintenance
- Latest release
- v8.5.1
- Oct 9, 2026 (1 month ago)
- CI on develop
- Not available right now
- GitHub Actions status
From the package's releases and its GitHub Actions. A passing run means the test suite passed on develop, on every PHP version it supports; it isn't a security review, and each release line has its own runs on GitHub. Checked hourly.
A quick look
Add the trait and every case answers its own is…() check, whatever style its name is written in.
1use Pharaonic\SmartEnum\SmartEnum; 2 3enum OrderStatus: string 4{ 5 use SmartEnum; 6 7 case PENDING = 'pending'; 8 case IN_PROGRESS = 'in_progress'; 9 case OUT_FOR_DELIVERY = 'out_for_delivery';10 case Delivered = 'delivered';11}12 13$status = OrderStatus::IN_PROGRESS;14 15$status->isInProgress(); // true16$status->isOutForDelivery(); // false17$status->in(['pending', 'in_progress']); // trueEverything your enums are missing
One trait, added to the enums you already have.
isActive() for Every Case
Each case gets its own check, named from the case: isActive() for Active, isInProgress() for IN_PROGRESS, isOnHold() for onHold.
Names, Values & Labels
names(), values() and labels() list your cases in the shape you need.
Select Options
options() maps each backing value to its label, ready for a dropdown.
Lookup by Case Name
fromName(), tryFromName() and hasName() work with case names, the way from() works with values.
Strict Comparisons
eq(), is(), isNot(), in() and notIn() match a case, a case name or a backing value, with no type juggling.
Unit & Backed Enums
The same trait works on unit, string-backed and int-backed enums, and custom labels flow into labels() and options().
Resources
- DocumentationInstallation, configuration and every API, per version.
- Source on GitHubRead the code, star it, or watch for releases.
- PackagistVersions and install statistics.
- Release notesWhat changed in each release.
- Report an issueFound a bug or missing a feature? Tell us.
- ContributeOpen a pull request; every contributor is credited.
Smart Enum Questions
Quick answers about installing and using Smart Enum.
What is Smart Enum?
One trait that adds framework-independent helpers to native PHP enums, such as names, values, labels, options, lookup by case name, strict comparisons and isActive() style case checks, without replacing cases(), from() or tryFrom(). It's a free, open-source PHP package by Pharaonic.
How do I install Smart Enum?
Run composer require pharaonic/php-smart-enum in your project's root directory.
What does Smart Enum require?
The latest release requires PHP 8.5.
Does it replace cases(), from() or tryFrom()?
No. Those methods belong to PHP and stay untouched. Smart Enum only adds new helpers next to them.
Does it work with unit (non-backed) enums?
Yes. A unit enum has no backing values, so values(), options(), hasValue() and info() use the case names instead.
How do I customize labels?
Declare a label() method in the enum, or define a global smart_enum_label() function for every enum at once. labels(), options() and info() pick the change up.
How does IN_PROGRESS become isInProgress()?
The check is is plus the case name, with each underscore-separated word capitalized. A word written all in upper case is title-cased first, so IN_PROGRESS becomes isInProgress(), PENDING becomes isPending() and onHold becomes isOnHold().
Will my IDE know about $status->isActive()?
The is<Case>() checks are resolved at runtime, so add @method bool isActive() tags to the enum's docblock for IDEs and PHPStan.
Does it work with Laravel?
Yes. It's plain PHP, so it works in any framework, and it has no Laravel-specific code.
Is Smart Enum free to use?
Yes. Smart Enum is open source under the MIT license, so you can use it in personal and commercial projects.
Where can I find the Smart Enum documentation?
Read the Smart Enum documentation for setup, usage, and the full API reference.
How do I report a bug or contribute to Smart Enum?
Open an issue or a pull request on GitHub, or ask in the Pharaonic Discord.
Ready to dig in?
Read the full documentation for installation, the static and instance helpers, case checks, custom labels, unit vs backed enums, the API reference, and examples.