PHP Classes
elePHPant
Icontem

File: EnumTest.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Ahmed Magdy Ezzeldin  >  PHP Enum Const  >  EnumTest.php  >  Download  
File: EnumTest.php
Role: Example script
Content type: text/plain
Description: Example Script
Class: PHP Enum Const
Provide enumerated values using class constants
Author: By
Last change:
Date: 1 year ago
Size: 926 bytes
 

Contents

Class file image Download
<?
require("Enum.php");

/*
There are 2 ways to declare a new Enum: One uses the utility function enum()
The other one is by creating a class that extends Enum and enum items are put
as constants inside the Enum
*/

/*
enum('Month', array(
        'January' => 1,
        'February' => 2,
        'March' => 3,
        'April' => 4,
        'May' => 5,
        'June' => 6,
        'July' => 7,
        'August' => 8,
        'September' => 9,
        'October' => 10,
        'November' => 11,
        'December' => 12
    )
);
/*/
class Month extends Enum {
    const
January = 1;
    const
February = 2;
    const
March = 3;
    const
April = 4;
    const
May = 5;
    const
June = 6;
    const
July = 7;
    const
August = 8;
    const
September = 9;
    const
October = 10;
    const
November = 11;
    const
December = 12;
}
//*/





// Test code
function process (Month $enum) {
    print
$enum->getName() . " => " . $enum->getValue() . "\n";
}

process(Month::December());

foreach(
Month::getKeys() as $k => $v) {
   
process($v);
}