This question already has an answer here:
- Dynamic constant name in PHP 3 answers
Let me explain with a real example:
class Config{
const DB_NAME = "FOO";
}
class ConfigLoader{
public static function get($key) {
return Config::$key;
}
public static function getTest() {
return Config::DB_NAME;
}
}
ConfigLoader::get("DB_NAME"); // return error: Access to undeclared static property
ConfigLoader::getTest(); // It's OK! return FOO
But i need to do something like ConfigLoader::get("DB_NAME) method
</div>