Is there any possibility to create a configuration file with global variables that are visible inside the class? Something similar to this:
config.php:
Your problem is that you are trying to use an expression in the class definition here:
class DB
{
private $_config = array($config['host_address'], ...
That is syntactically incorrect (you can only use constant values for that), and I wouldn't expect it to locate the intended scope there. What you should do instead is initialize this property in the construtor instead:
class DB
{
private $_config;
function __construct() {
global $config;
$this->_config = array($config['host_address'], $config['username'], $config['password'], $config['name']);
}
Or even lazier, just use include('config.php');
in place of the global $config
alias. That way your config script will extract $config as local variable within the constructor, which is all you need.