常量已在php中定义

时间:2011-05-04 17:01:30

标签: php constants

我有一个我正在尝试运行的功能,但它显示的消息为 CONSTANT已定义。

我试图提出一个条件,说“如果已定义”关于该功能,但仍然没有。有没有方法可以忽略这个并看到输出?

3 个答案:

答案 0 :(得分:99)

替换它:

define('constant', 'value');

用这个:

if (!defined('constant')) define('constant', 'value');

答案 1 :(得分:3)

define()

示例:

/* Note the use of quotes, this is important.  This example is checking
 * if the string 'TEST' is the name of a constant named TEST */
if (defined('TEST')) {
    echo TEST;
}

答案 2 :(得分:0)

这是你检查常数的方法:

if (defined('TEST')) {
    echo TEST;
}

也许你没有正确地进行检查或者你正在检查的常量不是错误的原因,一些流氓包含文件可能有不同的常量并产生重叠/重新定义。