The myclabs/php-enum library is a PHP package that provides an object-oriented approach to implementing enumerations, inspired by the SPL's SplEnum. Before PHP 8.1 introduced native enum support, this library offered a structured way to define and use enumerated types, enhancing code readability and type safety. By extending the base Enum class, developers can create enums with defined constants, ensuring that variables only hold valid, predefined values. This approach helps prevent errors related to invalid values and makes the codebase more maintainable.

Features

  • Define enumerated types by extending the base Enum class
  • Access enum values using static methods corresponding to constant names
  • Validate values against the defined set of enum constants
  • Retrieve all possible enum values and keys as arrays
  • Compare enum instances for equality using the equals() method
  • Serialize enum instances to JSON for data interchange

Project Samples

Project Activity

See All Activity >

Categories

Libraries

License

MIT License

Follow PHP Enum

PHP Enum Web Site

Other Useful Business Software
MongoDB Atlas runs apps anywhere Icon
MongoDB Atlas runs apps anywhere

Deploy in 115+ regions with the modern database for every enterprise.

MongoDB Atlas gives you the freedom to build and run modern applications anywhere—across AWS, Azure, and Google Cloud. With global availability in over 115 regions, Atlas lets you deploy close to your users, meet compliance needs, and scale with confidence across any geography.
Start Free
Rate This Project
Login To Rate This Project

User Reviews

Be the first to post a review of PHP Enum!

Additional Project Details

Programming Language

PHP

Related Categories

PHP Libraries

Registered

2025-05-15