How to check if a class constant exists?

Reading Time: < 1 minute

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

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept the Privacy Policy

This site uses Akismet to reduce spam. Learn how your comment data is processed.