我创建了一个包含用户名和密码的配置文件,用于连接到我的数据库。
我以这种方式在类DatabaseService的构造函数中传递这个配置文件:
function __construct(){
require __DIR__ .'../../../../config/db.config.php';
$this->username = $db_config['username'];
}
在构造函数中创建用户名后,是否有方法将其设置为受保护?(请记住,属性值基于外部文件中的变量集)
感谢
protected username;
function __construct(){
require __DIR__ .'../../../../config/db.config.php';
$this->username = $db_config['username'];
}