I am currently writing a program in php. I want to let the user of my script change some settings, like database location and user.
These variable are placed on the first lines of the script.
Now i want to access these variables from everywhere of the script like in classes and functions.
I used globals for this. But a colleague told me not to use globals.
So what is the common way to store and access settings in php?
You could use constants which are global by default:
Otherwise you could use a Registry Singleton class in which you load the settings and store them in a class private variable.
Classic Registry class structure:
And no, I suggest you not to use Injections and stuff patterns. Just use Singleton. With Injection you get everything worse and more complicated.