These are not PHP global variables, they are constants that cannot be modified(hence the name).
Trying to redefine them, using a define()
will trigger a notice since they are already defined(and consequently keep the initial value assigned). To stay away from notices, you should check if they have been defined()
before.
Example:
define('VARIABLE', 'hello');
define('VARIABLE', 'world');
echo VARIABLE;
Results:
Notice: Constant VARIABLE already defined in **your-file** on line xxx
hello
In this case the variable won’t be updated to world
.
Example using defined()
:
define('VARIABLE', 'hello');
if(!defined('VARIABLE')){
define('VARIABLE', 'world');
}
else{
echo "VARIABLE HAS ALREADY BEEN DEFINED.<br />";
}
echo VARIABLE;
Results:
VARIABLE HAS ALREADY BEEN DEFINED.
hello
In this case you can specify an action to perform in case that constant has already been defined.