php 单例模式

来源:互联网 发布:fm调频发射器软件 编辑:程序博客网 时间:2024/06/10 20:02
<?php
/**
 * Created by PhpStorm.
 * User: SmallFukki
 * Date: 2017/11/15
 * Time: 21:28
 */


/**
 * 单例模式
 */


class Singleton{
    //存放实例
 private static $_instance = null;
 //私有化构造方法、
 private function __construct(){
    echo "单例模式的实例被构造了";
 }
// 私有化克隆方法
 private function __clone(){ }
//公有化获取实例方法
 public static function getInstance(){
     if (!(self::$_instance instanceof Singleton)){
        self::$_instance = new Singleton();
     }
     return self::$_instance;
     }
 }
 $singleton=Singleton::getInstance();
原创粉丝点击