私は最近、シングルトンが悪いことを知りました。現在のコードをシングルトンなしで再作成する方法の答えが見つかりませんでした。
私が今持っているもの:
class checker {
private static $inst;
public static function getInst() {
if(!isset(self::$inst))
throw new Exception("Error 13: Check module not started.");
else
return self::$inst;
}
function __construct() {
if(!isset(self::$inst))
self::$inst = $this;
else {
throw new Exception("Error 10: Checker not ready?");
exit;
}
}
}
そして、私は使用します
checker::getInst()->blaBlaFunction();
複数のクラスで必要であり、そのインスタンスは 1 つだけです。