What's the best practice to access config from functions and classes? The below code is working, but it seems the wrong way.
How I could improve this? I'm free to change every part.
config.php
return [
'ENVIRONMENT' => 'development',
'DB_HOST' => '127.0.0.1'
];
index.php
$config = require 'config.php';
$config = (object) $config;
...
$router->get('/test/user/create', function() {
global $config;
$login = new \Demo\Login($config);
...
_view('main');
});
...
function _view($page){
global $config;
header('Content-Type: text/html; charset=utf-8');
require_once('../view/'.$page.'.php');
}
Login.php
public $config = '';
public function __construct($config) {
$this->config = $config;
echo $this->config->ENVIRONMENT;
}