/** * Ensures there is only one instances of LEM. Note, if switch between surveys, have to clear this cache * @return LimeExpressionManager */ public static function &singleton() { $now = microtime(true); if (isset($_SESSION['LEMdirtyFlag'])) { $c = __CLASS__; self::$instance = new $c(); unset($_SESSION['LEMdirtyFlag']); } else { if (!isset(self::$instance)) { if (isset($_SESSION['LEMsingleton'])) { self::$instance = unserialize($_SESSION['LEMsingleton']); } else { $c = __CLASS__; self::$instance = new $c(); } } else { // does exist, and OK to cache return self::$instance; } } // only record duration if have to create (or unserialize) an instance self::$instance->runtimeTimings[] = array(__METHOD__, microtime(true) - $now); return self::$instance; }