In PHP, to check if a constant exists we use the defined
function. As below, for the two cases of constant declaration:
const MY_TEST_1 = 'my test 1';
define('MY_TEST_2', 'my test 2');
var_dump(defined('MY_TEST_1'), defined('MY_TEST_2')); // true, true
And when I declare a constante
in a namespace
or a classe
? How do I check the existence of these?
namespace StackOverflow {
const LANG = 'pt-br';
class StackOverflow
{
const MY_CONSTANT = 'minha constante';
}
}
From the example above, how would you check for StackOverflow\LANG
and StackOverflow\StackOverlow::MY_CONSTANT
?