<?PHP define("MAX",10000); if (defined("MAX")) echo "defined"; //defined if (defined("M_PI")) echo "defined"; //defined $max = 100; if (defined("max")) echo "defined"; else echo "not defined"; //not defined ?>
The parameter must be quoted, otherwise FALSE will be returned.
<?PHP define("MAX",10000); if (defined(MAX)) echo "defined"; else echo "not defined"; //not defined if (defined(M_PI)) echo "defined"; else echo "not defined"; //not defined ?>
To check whether a variable is declared or not, use function
<?PHP $max = 100; if (isset($max)) echo "declared"; //declared else echo "not declared"; $max = NULL; if (isset($max)) echo "declared"; else echo "not declared"; //not declared ?>
To check whether a function has been defined or not, use function
<?PHP if (function_exists("preg_split")) echo "defined"; //defined else echo "not defined"; function uppercasestr($str) { $str = strtolower($str); $elem = explode(" ",$str); $str = ""; foreach($elem as $word) { if ($str == "") $str .= ucfirst($word); else $str .= " " . ucfirst($word); } return $str; } if (function_exists("uppercasestr")) echo "defined"; //defined else echo "not defined"; ?>
Some PHP predefined constants are listed below. For more PHP predefined constants, please check constants.