constant already defined in php

PhpConstants

Php Problem Overview


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?

Php Solutions


Solution 1 - Php

Replace this:

define('constant', 'value');

with this:

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

Solution 2 - Php

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

Solution 3 - Php

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJDesignsView Question on Stackoverflow
Solution 1 - PhpOZ_View Answer on Stackoverflow
Solution 2 - PhpPhill PaffordView Answer on Stackoverflow
Solution 3 - PhpJakubView Answer on Stackoverflow