Wednesday, February 4, 2015

[php] php Constant already defined

IF you found the your constant was already defined in php, the Error message:
Constant MINS already defined

you should add some code to check if your constant was defined not.

From this:
define('constant', 'value');
To this:
if (!defined('constant')) define('constant', 'value');
An Example:
<?php
define('MIN', '5');
echo '<hr /><h2>Have not check constant.</h2>';
echo MIN;
define('MIN', '5');
echo '<hr /><h2>Checked constant.</h2>';
if (!defined('MIN')) define('MIN', '5');
echo MIN;
?>
Result:


Reference:
http://stackoverflow.com/questions/5887108/constant-already-defined-in-php

No comments :

Post a Comment