Answer the question
In order to leave comments, you need to log in
Can require_once be used in this case?
I have some Kernel class where I am going to store the main application settings and inherit this class by other classes if necessary.
there is a settings property and a file connection where these settings are stored through the constructor, naturally through require_once, since I only need to connect it once
class Kernel {
public $settings;
public function __construct() {
$this->settings = require_once __DIR__.'../config.php';
}
}
Answer the question
In order to leave comments, you need to log in
class Settings {
private $settings;
private static $instance;
public static getInstance() {
if (!self::$instance) self::$instance = new self();
return self::$instance;
}
public function getSettings() {
return $this->settings;
}
private function __construct() {
$this->settings = ...
}
}
class Kernel {
protected $settings;
public function __construct() {
$this->settings = Settings::getInstance()->gteSettings();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question