我正在尝试在PHP中实现单例,但出于某种原因,每次静态变量“$ instances”为null并且它都会被重新初始化。
class Enteliprint_Model_EnteliService {
public static $instances;
static public function getSingltoneInstances() { DebugBreak();
if (NULL == Enteliprint_Model_EnteliService::$instances) {
$result = array();
foreach (Enteliprint_Model_EnteliPrint::getEnteliPrintInstances(True) as $instance) {
$associatedSceddules = json_decode($instance['AssocSchedules']);
$scheduleIDs = '-1,';
foreach ($associatedSceddules as $key=>$schedule) {
$scheduleIDs = $scheduleIDs.($key > 0 ? ', ' : '').$schedule->ID;
}
$instance['AssocFilters'] = Enteliprint_Model_EnteliFilter::getEnteliFilternstances($scheduleIDs);
$result[] = $instance;
}
Enteliprint_Model_EnteliService::$instances = $result;
}
return Enteliprint_Model_EnteliService::$instances;
}
public static function sendEvents($events) {
$instances = Enteliprint_Model_EnteliService::getSingltoneInstances();
有什么想法吗?