Rumah > Soal Jawab > teks badan
class test { private static $instance; private function __construct() { echo 2; } public static function getInstance() { if( !( self::$instance instanceof self ) ) { echo 1; self::$instance =new self(); } return self::$instance; } private function __clone() { } }
test::getInstance(); //12
self::$instance =new self() 这里实例存不进静态私有变量里面啊,怎么实现单例?还是我哪里写错了?