constant already defined in php

江枫思渺然 提交于 2020-01-28 18:11:08

问题


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

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?


回答1:


Replace this:

define('constant', 'value');

with this:

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



回答2:


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



回答3:


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.



来源:https://stackoverflow.com/questions/5887108/constant-already-defined-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!