时间:2021-07-01 10:21:17 帮助过:12人阅读
class CartTool
{
private static $ins;
private $good = array();
final private function __construct()
{
}
final private function __clone()
{
}
// 获取实例
protected static function getIns()
{
if(!(self::$ins instanceof self))
{
self::$ins = new self();
}
return self::$ins;
}
/**
* 函数作用:把购物车的单例对象放到session里
*
*
* @return instance 购物车的单例对象
* */
public static function getCart()
{
if(!isset($_SESSION['cart']) || !($_SESSION['cart'] instanceof self))
{
echo '1';
$_SESSION['cart'] = self::getIns();
}
return $_SESSION['cart'];
}