I am working on a function to validate variables and constants.
function checkVars($var){
if(isConstant($var)){ <--here is my problem, how do I check if its a Constant and or a string?
return defined($var);
}else{
//use other functions to check if its a valid variable
}
}
Is there a way to check if its a string or a constant?
EDIT: The idea behind this is to save lines of code on recurring tasks like:
if(defined('CONS')){
if(CONS > 0 && CONS !== false){
//and so on..
}
}
This is just an example but you could have 4 lines of code just to validate a constant or a variable to fit specific application needs.
The idea is to save all that work with a single function call that returns true or false:
if(isValid('CONS')){
//do stuff on true
}else{
//do stuff on false
}
is_string()didnt work for you here?defined(name_of_constant)and you can check the value of the constant usingconstant(name_of_constant)