Everybody has it, an array or object that needs accessing throughout your entire project. This can be settings, an array of user data or anything else that does not qualify for for a defined variable (cause defined array's are bad m'kay).
I'm probably not looking for the right type of thing, but I need a way to access an object in every class, function or page.
So for example sake, lets say I have a standard config file with this:
<?php
return array(
'database' => array(
'driver' => 'mysql',
'mysql' => array(
'host' => 'localhost',
...
),
'mongodb' => array(
'host' => 'localhost',
...
),
...
),
);
?>
I get it by doing:
$config = (require('path/file.php'));
So, now I have my config. But this doesn't pass around. I don't want to call "$config = (require('path/file.php'));" everytime I need a setting.
So is there a way to always call this only once by, for example, storing it in a class or something (without having to define that class all the time obviously, cause that defeats the point).
Now I know about globals. But I'm not really partial to them for several reasons. Mysql is not an option cause it's a config file and users need to be able to alter it before launch.