JDesigns
JDesigns

Reputation: 2332

constant already defined in php

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?

Upvotes: 58

Views: 105286

Answers (3)

user680786
user680786

Reputation:

Replace this:

define('constant', 'value');

with this:

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

Upvotes: 153

Phill Pafford
Phill Pafford

Reputation: 85298

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

Upvotes: 3

Jakub
Jakub

Reputation: 20475

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.

Upvotes: 0

Related Questions