单例模式复习
1 /** 2 * 單例模式 3 */ 4 class Single 5 { 6 protected static $ins = null; 7 8 if(self::$ins === null) 9 { 10 self::$ins = new Single(); 11 } 12 13 return self::$ins; 14 15 //防止外部調(diào)用并且防止繼承后重寫 16 final protected function __construct(){} 17 18 //防止外部克隆并且防止繼承后克隆 19 final protected function __clone(){} 20 21 }
使用場景:數(shù)據(jù)庫類,一般的小中型項目就一臺mysql服務(wù)器想連接數(shù)據(jù)庫的話就用一個對象去連接就好了。
轉(zhuǎn)載于:https://www.cnblogs.com/qt0909/p/10676590.html
總結(jié)
- 上一篇: phpStudy mysql升级至5.7
- 下一篇: 微信客服系统开发SDK使用教程- 拉取当