After a few years in PHP development, I saw and heard various ways for storing "global scope data" (globals, constants, ini/XML/YML files, database, singleton properties...).
By "global scope data", I mean:
- Global application/project settings such as
- Database configuration
- SMTP, FTP parameters
- Database identifiers (e.g. primary key values for specific languages or countries defined in DB)
- Global runtime settings such as
- Enable logging / debug
- Environment is dev / test / prod
- etc.
... which are not supposed to change once retrieved, and need to be easily reachable in any part of the project code.
Some global data may need to be stored as associative array (so cannot be declared as constant).
For example: date formats per language. BTW, I saw this other SO question about array constants, but isn't there something more readable than using unserialize
everywhere an array constant value is needed?
My main question is: what is the way you would recommend to store properly (I mean clean, readable, reliable) global scope data, and why (pros/cons)?
Thanks.
parse_ini_file
andarray_merge
. And if it could actually be used to update the settings file (more frequent topic on SO), it probably would kill the user comments still. – Damiondamita