zoukankan      html  css  js  c++  java
  • PHP单例模式 demo

    <?php

    class single{

       static public $db;

       private function __construct(){

       };

        static function getinstance(){

             if(!self::$db)

                 self::$bd = new self();

           return self::$db;

       }

    }

    single::getinstance();

    //demo 2

    class pzhang{

      static private $instance;

      private $config;

      private function __construct($config){

          $this->config = $config;

          echo "我被实例化了";

      }

     private function __clone(){

    }

     static public function getInstance($config){

          if(!self::$instance  instanceof self)

               self::$instance = new self($config);

        return self::$instance;

     }

     public function getname(){

       echo $this->config;

    }

    }

    $adb = pzhang::getInstance(1);

    $adb->getname();

    //结果   我被实例化了1

    ?>

  • 相关阅读:
    网站添加背景音乐
    解决项目上的红色感叹号
    1.12那些年你不知道的爬虫面试题
    1.11you-get 视频爬取
    1.10pytesseract
    1.9Pyppeteer
    1.8request-html
    1.7XPath
    1.6Selenium XPath
    1.5cookies
  • 原文地址:https://www.cnblogs.com/isuansuan/p/9754528.html
Copyright © 2011-2022 走看看