тут изначально очень не правильный подход. не нужно делать "дефолтную конфигурацию" через глобальные переменные.
class DbConnection
{
private string $userName;
private string $password;
private string $dbname;
public function __construct(string $userName, string $password, string $dbName)
{
$this->userName = $userName;
$this->password = $password;
$this->dbname = $dbName;
}
}
class AuthController
{
private DbConnection $dbConnection;
public function __construct(DbConnection $connection)
{
$this->dbConnection = $connection;
}
}
$dbSettings = include('dbconfig.php');
$connection = new DbConnection($dbSettings['login'], $dbSettings['password'], $dbSettings['dbName'] );
$controller = new AuthController($connection);
а в файле dbconfig.php
return [
'login'=>'myLogin',
'password'=>'myPassword',
'dbName'=>'myDbName'
];