You may find that if you use <?= ?> to dump your constants, and they are not defined, depending on your error reporting level, you may not display an error and, instead, just show the name of the constant. For example:
<?= TEST ?>
...may say TEST instead of an empty string like you might expect. The fix is a function like this:
<?php
function C(&$constant) {
$nPrev1 = error_reporting(E_ALL);
$sPrev2 = ini_set('display_errors', '0');
$sTest = defined($constant) ? 'defined' : 'not defined';
$oTest = (object) error_get_last();
error_reporting($nPrev1);
ini_set('display_errors', $sPrev2);
if ($oTest->message) {
return '';
} else {
return $constant;
}
}
?>
And so now you can do:
<?= C(TEST) ?>
If TEST was assigned with define(), then you'll receive the value. If not, then you'll receive an empty string.
Please post if you can do this in fewer lines of code or do something more optimal than toggling the error handler.