2
I see in many codes out there programmers that setam a constant and in the document itself check whether this constant exists (was defined) in itself. I would like to know why this happens.
When we download open source from the forum platform phpBB3, and open the file install/database_update.php
, right in the first lines we notice this:
if (defined('IN_PHPBB') && defined('IN_INSTALL'))
{
$updates_to_version = UPDATES_TO_VERSION;
$debug_from_version = DEBUG_FROM_VERSION;
$oldest_from_version = OLDEST_FROM_VERSION;
return;
}
define('IN_PHPBB', true);
define('IN_INSTALL', true);
In almost all files found for download in the code of phpBB3
, there is this constant define('IN_PHPBB', true);
being defined at the beginning of the code.
This is the main example I can remember to clarify my doubt.
Based on this code (and some others I’ve seen around, but I won’t have a hand), is there any particular reason for this? It’s some kind of good safety practice?
I would say that if the
define
and theif
are in the same file does not make much sense. But when we have "includes" and those lines are in different files then it is good practice. Take a look at a similar question: http://answall.com/q/43650/129– Sergio
You could link some examples to show a context.
– Maniero
@bigown, I have "at hand" here just the example of phpBB3, although I have seen it elsewhere.. I tried to elucidate my question better.
– waghcwb