How can I check if a constant is defined in a PHP class?
class Foo {
const BAR = 1;
}
Is there something like property_exists()
or method_exists()
for class constants? Or can I just use defined("Foo::BAR")
?
Yes, just use the class name in front of the constant name:
defined('SomeNamespace\SomeClass::CHECKED_CONSTANT');