Generally speaking I prefer .ini
or XML configuration files. In larger systems, often someone other than the developer will need to change a configuration value, possibly a DBA or a sysadmin. Most DBAs and sysadmins I know wouldn't have any problem navigating through a simple PHP script, but I would prefer if they didn't. One small mistake in there can harm the whole application in quite a few ways.
But in smaller systems, it's extremely convenient to use PHP scripts for configuration. I was playing around with the AWS SDK today, which also uses a PHP script for configuration:
CFCredentials::set(array(
'development' => array(
'key' => 'xxx',
'secret' => 'xxxx',
'default_cache_config' => sys_get_temp_dir(),
'certificate_authority' => true
),
'@default' => 'development'
));
Instead of hardcoding a default_cache_config
, I'm passing the system temp, and that would work in every system I deploy the script. This script is a small proof of concept that will be passed around 10 developers, and I want them to run it as is, withouth having much to think about. If the prototype evolves, I'll hardwire it with my XML configuration class (and obviously won't rely on filesystem cache).