Since constant are global and accessible from any file once they are defined, i was wondering where to define them. People can access a site on many different pages... Does each page have to define all constants ? Or is it best to make one file constants.inc and include them on any page? Or what other options are there?
I have a 'constants.php' file and it is included in all my scripts. A few other php software packages I have seen also do this. I prefer to have them all defined in one file instead of doing it on each page.
you definitely want to define all your constants in a single script and include it in every other page
It is better to define them all in one file and then include that file into your project. This way you won't run into conflicts by forgetting that you have defined XYZ in three different files, etc.
in fact, it's best to group things as much as you can, eg all functions in one file, all classes in one files, etc, etc
You can also do $bla = 'xyz'; function my_function() { echo $GLOBALS['bla']; } my_function(); PHP: That would echo 'xyz'.