PHP 单例
2020-11-15 09:08
标签:com http class blog style div img code java javascript tar PHP 单例,布布扣,bubuko.com PHP 单例 标签:com http class blog style div img code java javascript tar 原文地址:http://www.cnblogs.com/ligangming/p/3698240.html 1 php
2
3 session_start();
4
5 class CartTool {
6 private static $ins = null;
7 private $items =array();
8 public $sign=0;
9
10 final protected function __construct(){
11 $this->sign=mt_rand(1,100000);
12 }
13
14 final protected function __clone(){
15
16 }
17
18 protected static function getIns(){
19 if(!(self::$ins instanceof self)){
20 self::$ins = new self();
21 }
22 return self::$ins;
23 }
24
25 public static function getCart(){
26 if(!isset($_SESSION[‘cart‘]) || !($_SESSION[‘cart‘] instanceof self)){
27 $_SESSION[‘cart‘]=self::getIns();
28
29 }
30
31 return $_SESSION[‘cart‘];
32 }
33
34
35 }
36
37
38 print_r(CartTool::getCart());
39
40 ?>
上一篇:.NET 性能分析工具