A simple and opinionated collection of PHP enum helpers inspired by https://github.com/archtechx/enums and https://github.com/BenSampo/laravel-enum. This package is framework agnostic, but if you use Laravel consider using this linked package https://github.com/datomatic/laravel-enum-helper and https://github.com/datomatic/laravel-enum-collections.

Construct enum by name or value: from(), tryFrom(), fromName(), tryFromName(), fromValue(), tryFromValue() methods

In all examples we'll use the classes described below: use Datomatic\EnumHelper\EnumHelper; // Pure enum enum PureEnum { use EnumHelper; case ACCEPTED; case DISCARDED; } enum PascalCasePureEnum { use EnumHelper; case Pending; case Accepted; case Discarded; case NoResponse; } // BackedEnum enum StringBackedEnum: string { use EnumHelper; case ACCEPTED = 'A'; case DISCARDED = 'D'; } enum IntBackedEnum: int { use EnumHelper; case ACCEPTED = case DISCARDED = case NO_RESPONSE = }
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners