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:
... 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.
You can look at Zend_Config for the most frequent implementations of config.
Of course array may seem the most immediate and uncomplicated solution since it's pure PHP and doesn't need any special parser or writer.
On the other hand the other formats have clear advantages too. The Zend_Config documentation writes for example about ini files.
The INI format is specialized to provide both the ability to have a hierarchy of configuration data keys and inheritance between configuration data sections. Configuration data hierarchies are supported by separating the keys with the dot or period character (".").
Using constants is not a good idea because: