PHP Classes

PHP Enum Const: Provide enumerated values using class constants

Recommend this page to a friend!
  Info   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 215 All time: 8,295 This week: 178Up
Version License PHP version Categories
php-enum-const 1.0Freely Distributable5.3PHP 5, Data types


This class can provide enumerated values using class constants.

It provides a base class that should be extended by a class that defines the enumerated values as class constants.

The class can set or get the complete list of supported enumerated constants, return the enumerated name as an object string value, as well the respective value using the getValue function.

Innovation Award
PHP Programming Innovation award winner
March 2014

Prize: One book of choice by Packt
Enumerated types are often used to pass values that must be set to a certain set of values.

This class implements enumerated types by using reflection to get the constants of a class and use their values to define the set of accepted values of an enumerated type.

This way developers only need to define the class constants to determine which are the values accepted in the enumerated type.

Using classes as enumerated values also makes it easy to benefit from type hinting to validate the types of values passed to functions that takes enumerated types as parameters.

Manuel Lemos
Picture of Ahmed Magdy Ezzeldin
  Performance   Level  
Name: Ahmed Magdy Ezzeldin <contact>
Classes: 4 packages by
Country: Egypt Egypt
Age: 43
All time rank: 6326 in Egypt Egypt
Week rank: 683 Down13 in Egypt Egypt Down
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

  Files folder image Files  
File Role Description
Accessible without login Plain text file Enum.php Class Include the enum class in your code to use it
Accessible without login Plain text file EnumTest.php Example Example Script
Accessible without login Plain text file License Lic. Apache License v2.0

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:8,295
This week:178Up