Created
December 4, 2013 07:25
-
-
Save samundra/7783609 to your computer and use it in GitHub Desktop.
Illustrations::Dynamically Accessing const class variable in PHP
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 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