constant() Function used as getter function to get the constant
in PHP , define the constant with the define function
define("IAMCONSTANT","Yes");
now you can get it by two way :
1.either use direct name of constant like this :
echo IAMCONSTANT;
it will print Yes
2. Use constant() Function :
echo constant("IAMCONSTANT");
it will print Yes
if constant is not defined than it will return null
echo constant("IAMNOTCONSTANT");
"IAMNOTCONSTANT" is not defined so it will print nothing
if you want to avoid the empty print or any check about constant is exist or not.
you can use defined method to do so
if(!defined("IAMNOTCONSTANT")){
//not defined constant so lets define it
define("IAMNOTCONSTANT","NO");
}