PHP defined() 用于检测一个给定的常量是否被定义,如果被检测的常量已定义则返回 TRUE,否则返回 FALSE。
语法:
bool defined( string name )
例子:
<?php
define('CONSTANT', "你好!");
if(defined('CONSTANT')){
echo '常量 CONSTANT 已经被定义';
} else {
echo '常量 CONSTANT 还未被定义';
}
?>
运行该例子输出:
常量 CONSTANT 已经被定义