55

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?

5
  • 4
    Could you provide some code? Also, do you have any included files?
    – eykanal
    May 4, 2011 at 17:02
  • can you show us the code please?
    – James C
    May 4, 2011 at 17:02
  • actually, its connected to several things and in the error message i see "constant..." in 3-4 files (these are like settings file). i am not sure which code i can provide as there are many..
    – JDesigns
    May 4, 2011 at 17:04
  • 2
    Makse sure you are using if( defined('NAME') ) instead of if( defined(NAME) )
    – Robik
    May 4, 2011 at 17:04
  • which is the function name? have you tried changing it?
    – Cristian
    May 4, 2011 at 17:05

3 Answers 3

148

Replace this:

define('constant', 'value');

with this:

if (!defined('constant')) define('constant', 'value');
2
  • 1
    My IDE likes to make this not one line, so I short circuited it !defined('constant') && define('constant', 'value'); Jul 11, 2017 at 18:42
  • 4
    This is a little more elegant: defined('constant') or define('constant', 'value');
    – sieppl
    Aug 18, 2017 at 7:31
3

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.