When using constants, which is best practice, if any? To set values as 1/0 or true/false?
define('CACHE_ENABLE', 0, true);
define('LOG_ENABLE', 1, true);
or
define('CACHE_ENABLE', false, true);
define('LOG_ENABLE', true, true);
When using constants, which is best practice, if any? To set values as 1/0 or true/false?
define('CACHE_ENABLE', 0, true);
define('LOG_ENABLE', 1, true);
or
define('CACHE_ENABLE', false, true);
define('LOG_ENABLE', true, true);
If you have a boolean value which can only be true or false, use true
and false
.
If you have a numeric value which you want to use in math, or as a counter, or as a bitmask for several possible states beyond true/false, use an integer.
This is really the same as for all other variables, constants aren't anything special. The reason that makes sense is because it clearly signifies your intent.