constant already defined in php

前端 未结 3 1171
庸人自扰
庸人自扰 2020-12-24 11:32

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

相关标签:
3条回答
  • 2020-12-24 11:41

    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;
    }
    
    0 讨论(0)
  • 2020-12-24 11:46

    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.

    0 讨论(0)
  • 2020-12-24 11:56

    Replace this:

    define('constant', 'value');
    

    with this:

    if (!defined('constant')) define('constant', 'value');
    
    0 讨论(0)
提交回复
热议问题