Is it a good practice to initialize an object for an authentication class that does various stuff like register user, login user etc. inside a config file?
The config file mostly does stuff like setting db username, password and site name etc.
Please provide a reason if you don’t find this a standard practice. Just to let you know most of the code is procedural except for this particular class.
// MySQL connection settings
$db_host = "localhost";
$db_user = "someuser";
$db_pass = "some pass";
$db_name = "somedb";
// Name of the site
$site_name = "MyDomainName";
$auth = new auth();//initialize Authentication class
$auth->set_auth();//Check if user autorized
In my opinion this is not a good idea. A config file is for configuration, not for execution. I would put this code into a bootstrap.php, so, when you have to edit your code in the future, you know exactly where you can find your configurations and instantiations.
index.php:
bootstrap.php:
config.php: