第一种:
/** * 一定要写@return static * @return static */ public static function getInstance() { $className = get_called_class(); if (!isset(self::$_instance[$className])) { self::$_instance[$className] = new $className(); } return self::$_instance[$className]; }
然后写方法,比如:
调用的时候:
第二种:
先写方法:
可以直接调用: