定义一个常量,输出

define('RECOMMEND_IP', "127.0.0.1");
echo RECOMMEND_IP; // 127.0.0.1

不定义常量,输出当前字符串

echo TEST; // TEST

判断常量是否已定义,必须加引号

// 错误
define('RECOMMEND_IP', '127.0.0.1');
defined(RECOMMEND_IP) or define('RECOMMEND_IP', '59.39.34.22')  // PHP Notice:  Constant RECOMMEND_IP already defined on line 1

// 正确
define('RECOMMEND_IP', '127.0.0.1');
defined(‘RECOMMEND_IP’) or define('RECOMMEND_IP', '59.39.34.22')