How to check if a class constant exists?
This blog post is older than 4 years and may no longer be valid.
1 min read

How to check if a class constant exists?


Sometimes it’s useful to know whether a certain class constant exists or not.

This is a very quick and painless way to find that out:

if(defined('myClass::CONSTANT')) { 
    // CONSTANT is defined within myClass
} else { 
    // CONSTANT isn't defined within myClass
}