class DbConn { function DbConn($fromGetInstance=false) { if (M_E != $fromGetInstance) { trigger_error(‘The DbConn class is a Singleton,’ .’ please do not instantiate directly.’); } } function &getInstance() { $key = ‘__some_unique_key_for_the_DbConn_instance__’; if (!(array_key_exists($key, $GLOBALS) && is_object($GLOBALS[$key]) && ‘dbconn’ == get_class($GLOBALS[$key]) )) { $GLOBALS[$key] =& new DbConn(M_E); } return $GLOBALS[$key]; } }
class DbConn { function DbConn() { $token = ‘__some_DbConn_instance_create_semaphore__’; if (!array_key_exists($token, $GLOBALS)) { trigger_error(‘The DbConn class is a Singleton,’ .’ please do not instantiate directly.’); } } function &getInstance() { static $instance = array(); if (!$instance) { $token = ‘__some_DbConn_instance_create_semaphore__’; $GLOBALS[$token] = true; $instance[0] =& new DbConn; unset($GLOBALS[$token]); }