{ if (!isset(self::$_INSTANCES[get_called_class()]) || !self::$_INSTANCES[get_called_class()] instanceof static) { self::$_INSTANCES[get_called_class()] = new static(); } return self::$_INSTANCES[get_called_class()]; } private function __clone() { throw new Exception('clone error'); } } class Player extends SingletonBase { private $_user_id = null; protected function _init() { $this->_user_id = 19999; } } class Enemy extends SingletonBase { private $_enemy_id = null; protected function _init() { $this->_enemy_id = 29999; } } $player = Player::getInstance(); $enemy = Enemy::getInstance(); var_dump($player); var_dump($enemy);