refactoring - How to get rid of singletons in PHP -
i found out singletons bad. couldn't find answer how recreate current code without singleton.
what have now:
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; } } } and use
checker::getinst()->blablafunction(); i need in multiple classes , 1 instance of it.
Comments
Post a Comment