常量已在 php 中定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5887108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:48:06  来源:igfitidea点击:

constant already defined in php

phpconstants

提问by JDesigns

I have a function that I am trying to run but it shows the message as CONSTANT already defined.

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

I tried to put a condition saying "if defined" about the function but still nothing. Is there any method to ignore this and see the output?

我试图添加一个条件,说“如果已定义”关于该函数,但仍然没有。有什么方法可以忽略它并查看输出吗?

回答by OZ_

Replace this:

替换这个:

define('constant', 'value');

with this:

有了这个:

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

回答by Phill Pafford

define()

定义()

Example:

例子:

/* 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;
}

回答by Jakub

Is this how you check for constants:

这是您检查常量的方式:

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

Maybe you're not doing the check properly OR the constant you are checking for isn't the cause of the error, some rogue include file might have a different constant and produces an overlap / re-definition.

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