Is there a benefit of using one over the other ?
$lang = isset($_COOKIE['lang']) ? $_COOKIE['lang'] : 'en';
# OR
define("LANG" , isset($_COOKIE['lang']) ? $_COOKIE['lang'] : 'en');
Thanks
Is there a benefit of using one over the other ?
$lang = isset($_COOKIE['lang']) ? $_COOKIE['lang'] : 'en';
# OR
define("LANG" , isset($_COOKIE['lang']) ? $_COOKIE['lang'] : 'en');
Thanks
It depends on what you want to do. The value of the constant can't be change once it's defined. The variable can. This difference should make you choose the one you need.
Constants:
Variables:
In this case a constant is more appropriate. As you want to use the same value through your entire application, and you don't want it possibly changed by mistake.
Do notice programing languages have many features you don't need to use to implement an algorithem, but rather they are there to make the algorithem more readable, maintainable and less prone to get bugs. Constants are one of those type of features.