Created
October 21, 2010 12:51
-
-
Save bzikarsky/638426 to your computer and use it in GitHub Desktop.
Several examples for Enum.php {@see http://gist.github.com/638407}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Gender extends Enum | |
{ | |
protected static $enum = array( | |
'MALE' => array('male', 'm', 'Dear Mr.'), | |
'FEMALE' => array('female', 'f', 'Dear Ms.') | |
); | |
protected $address = ''; | |
protected $adjective = ''; | |
protected $short = ''; | |
protected function init($value, $short, $address) | |
{ | |
$this->value = $value; | |
$this->address = $address; | |
$this->short = $short; | |
} | |
public function getAddress() | |
{ | |
return $this->address; | |
} | |
public function getShort() | |
{ | |
return $this->short; | |
} | |
public function getValue() | |
{ | |
return $this->value; | |
} | |
} | |
class Month extends Enum | |
{ | |
protected static $enum = array( | |
'JANUARY', | |
'FEBRUARY', | |
'MARCH', | |
'APRIL', | |
'MAY', | |
'JUNE', | |
'JULY', | |
'AUGUST', | |
'SEPTEMBER', | |
'OCTOBER', | |
'NOVEMBER', | |
'DECEMBER' | |
); | |
} | |
$gender = Gender::MALE(); | |
$month = Month::get('JANUARY'); | |
echo $month, "\n"; | |
var_dump($month->isJanuary()); | |
var_dump($month->is('JANUARY')); | |
var_dump($month->is(Month::JANUARY())); | |
var_dump($month->isMarch()); | |
var_dump($month->is('March')); | |
var_dump($month->is(Month::MARCH())); | |
var_dump($month->is(Gender::MALE())); | |
echo $gender, "\n"; | |
echo $gender->getAddress(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment