php单例型(singleton pattern)
生活随笔
收集整理的這篇文章主要介紹了
php单例型(singleton pattern)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
搞定,吃飯
<?php /* The purpose of singleton pattern is to restrict instantiation of class to a single object. It is implemented by creating a method within the class that creates a new instance of that class if one does not exist. If an object instance already exists, the method simply returns a reference to an existing object. */class Logger {private static $instance;public static function getInstance() {if (!isset(self::$instance)) {self::$instance = new self;}return self::$instance;}public function logNotice($msg) {return 'logNotice: ' . $msg . '<br/>';}public function logWaring($msg) {return 'logWaring: ' . $msg . '<br/>';}public function logError($msg) {return 'logError: ' . $msg . '<br/>';} }echo Logger::getInstance()->logNotice('test-log-notice'); echo Logger::getInstance()->logWaring('test-log-waring'); echo Logger::getInstance()->logError('test-log-error'); ?>轉載于:https://www.cnblogs.com/aguncn/p/11179972.html
總結
以上是生活随笔為你收集整理的php单例型(singleton pattern)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 渣打银行信用卡额度多少?额度查询看这里
- 下一篇: 工行信用卡账单分期手续费是多少?2018