• 0

Accessing global variables inside an autoloader class?


Question

I have created a database class but it's not picking up the variables from my config file, i can't seem to get my head around it. I've snipped a lot of the code to keep it simple

 

index.php (requires the config file and attaches the config to the main file

$config = require_once 'config.php';
$config['app_dir'] = __DIR__ . '/';

// __autoload() classes here

$app = new Dispatch($config);

my config file has an array.

<?php
return [
  'db_host' => 'localhost',
  'db_user' => 'dbuser',
  'db_pass' => 'dbpass',
  'db_name' => 'dbname'
];

Now whenever i try to use something like $this->config['db_user'] it can't be found and throws an error.. i've tried adding global $config; into the class and the constructor, still nothing. 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

This topic is now closed to further replies.