How can undefined constants in PHP be properly addressed to avoid errors?

When dealing with undefined constants in PHP, it is important to properly address them to avoid errors. One way to do this is by using the defined() function to check if a constant is defined before using it. By checking if a constant is defined, you can prevent PHP from throwing an error when trying to access an undefined constant.

if (defined('CONSTANT_NAME')) {
    // Use the constant here
    echo CONSTANT_NAME;
} else {
    // Handle the case when the constant is undefined
    echo 'Constant is not defined';
}