I'm trying to define a constant, but I don't want to redefine it if it's already been defined. Here's a C sample:
#ifndef BASEPATH
#define BASEPATH /mnt/www
#endif
What is the most elegant way to do this in PHP?
Use defined()
and define()
.
if (!defined('BASEPATH')) {
define('BASEPATH', '/mnt/www');
}
if(!defined('BASEPATH')) {
define('BASEPATH', '/mnt/www');
}
http://us3.php.net/manual/en/function.defined.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With