I did a little benchmarking...
It looks like there's a significant speed difference when
writing each of these types. Running a loop of 10,000 iterations:
const = 3.19
define = 4.3
$var = 9.5
But
setting another variable to the value of the constant (technically, an array value for the test; eg, $foo[$i] = _VAR_) is also significantly different:
const = 36.01
define = 35.5
$var = 2.25
So I believe that writing a constant is faster, but reading a variable is faster. Granted, when we're talking about milliseconds over 10,000 iterations this is pretty insignificant, but if you have a script that's running a lot of iterations and time matters then it's worth knowing.
As far as I can tell, "const" would be the OK choice if you're strictly setting the value to text and don't need to use any variables, conditions, or functions. An example might be:
const _BASE_ = '/home/example';
"define()" would be the OK choice if you are setting the value to anything that's variable, is in a condition, or uses a function. An example might be:
define('_DBH_', @mysqli_connect('localhost', ...));
Otherwise, using a regular variable would be the best choice. And I'm not really convinced that using const or define() would ever be the "best" choice for a normal website.
****
One other difference that I found that may be noteworthy: I can't find a way to print the value of const or define() within an EOF. So while this works:
echo _BASE_;
this does not:
echo <<<EOF
first: _BASE_
second: {_BASE_}
EOF;
Both lines in the above just show the text "_BASE_" or "{_BASE_}" instead of the value of the constant. There might be another way to get them to print them within the EOF that I didn't consider, of course.
Based on all of the above, the only use I can think of for using a constant on my website would be as DBH (like my example above). But I need to do another speedtest to find out if a series of
mysqli_real_escape_string(_DBH_, $var) (for example) is faster than
mysqli_real_escape_string($dbh, $var). I'm hesitant to test it on my live database, though... anybody know of a sandbox website that'll let me connect to their database and run test queries?