Blogger Information
Blog 33
fans 0
comment 0
visits 26171
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP 设计模式之——单例模式
非常缪
Original
579 people have browsed it

/**
*单例模式示例
*/
final class Sigle{
 private static $ins = null;
 public static function getIns(){
   if(self::$ins === null){
     self::$ins = new self();
   }
   return self::$ins;
 }

 /**
  * 封锁重写和继承
  */
 final private function __construct(){
 }
 /**
  * 封锁克隆
  */
 final private function __clone(){
 }
}
$s1 = Sigle::getIns();
$s2 = Sigle::getIns();
if($s1===$s2){
   echo '是同一个对象';
}else{
   echo '不是同一个对象';
}



Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post