You are calling $DB_USER
from inside of your class method, which means you are actually calling the variable from the local scope (within the class). To fix this, just tell PHP that you're looking for the global variable by adding global $DB_USER
inside of your methods where it will be used (or use your constructor to add it to the class scope):
class Database
{
private $DB_USER = '';
private $DB_PASS = 'foob';
private $DB_DRIVER = 'foob_foob';
// snip
// Method 1: Add the variable to the class scope with the constructor
public function __construct()
{
global $DB_USER;
$this->DB_USER = $DB_USER;
}
// Method 2: tell PHP that you want the global variable in your methods
public function foo()
{
$global $DB_USER;
...
}
With method 1, you can now call $this->DB_USER
instead of $GLOBALS['DB_USER']
.
With method 2, you add global $DB_USER
to each, and then just use $DB_USER
.
For more information see http://php.net/manual/en/language.variables.scope.php