Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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