Skip to content

Instantly share code, notes, and snippets.

@samundra
Created December 4, 2013 07:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save samundra/7783609 to your computer and use it in GitHub Desktop.
Save samundra/7783609 to your computer and use it in GitHub Desktop.
Illustrations::Dynamically Accessing const class variable in PHP
<?php
class RegionVO {
const NSW = 35;
const ACT = 37;
const VIC = 38;
const QLD = 9;
const SA = 36;
const WA = 39;
const NT = 40;
const TAS = 26;
public static function getID($alias) {
$field = (string)strtoupper($alias);
return constant('RegionVO::'.$field);
}
}
echo RegionVO::getID('VIC').PHP_EOL;
echo RegionVO::getID('QLD').PHP_EOL;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment