I wanted to know if parsing the INI file in the constructor is ok or is there a more optimal process?
So my current process is to pass the INI file while instantiating the class like this:
include_once('/path/to/class.php');
$bar = new Foo('/path/to/class.ini');
$bar->runProcess();
So in my class constructor I have something like this:
public function __construct($ini_file) {
$ini = parse_ini_file($ini_file, true);
// Then set all the variables I need here from the INI
$this->variable_setting = $ini['ini_section']['ini_variable'];
}
Doing it in the constructor is fine. However, if you don’t always need it, you might want to do it in a separate method which is called only when the ini file is actually needed.