I am trying to make a small PHP function which can check if a constant is defined, and if so, echo it, and if not, echo space or nothing.
Right now, the if(defined()
part is not working, because the constant is being transferred to a variable inside the function.
function getConstant($constant) {
if(defined($constant)) {
echo constant($constant);
} else {
echo '';
}
}
The echo constant($constant)
part is working fine, but I cannot check if the constant is actually defined because it is a variable now.
I cannot seem to find a solution for it
$constant
must be a string with constant's name.