<?php class A { private static $obj; private $name; private function __construct() { } static public function getObj() { if (empty(self::$obj)) { return self::$obj = new A(); } return self::$obj; } public function setName($name) { $this->name = $name; } public function getName() { echo $this->name; } } $a = A::getObj(); $a->setName('test'); $a->getName(); echo '==='; unset($a); $b = A::getObj(); $b->getName();