PHP Classes

PHP Enum Const: Provide enumerated values using class constants

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 216 All time: 8,306 This week: 560Up
Version License PHP version Categories
php-enum-const 1.0Freely Distributable5.3PHP 5, Data types
Description 

Author

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
Winner


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: 44
All time rank: 6326 in Egypt Egypt
Week rank: 180 Up4 in Egypt Egypt Up
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

  Files folder image Files (3)  
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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:216
This week:0
All time:8,306
This week:560Up