Home > Backend Development > PHP Tutorial > php session购物车有关问题

php session购物车有关问题

WBOY
Release: 2016-06-13 12:33:17
Original
853 people have browsed it

php session购物车问题

<br />
class CartTool<br />
    {<br />
        private static $ins;<br />
        private $good = array();<br />
       <br />
        final private function __construct()<br />
        {<br />
            <br />
        }<br />
        final private function __clone()<br />
        {<br />
            <br />
        }<br />
        <br />
        // 获取实例<br />
        protected static function getIns() <br />
        {<br />
        if(!(self::$ins instanceof self)) <br />
        {<br />
            self::$ins = new self();<br />
        }<br />
<br />
        return self::$ins;<br />
    }<br />
        <br />
        <br />
        /**<br />
         * 函数作用:把购物车的单例对象放到session里<br />
         * <br />
         * <br />
         * @return instance 购物车的单例对象<br />
         * */<br />
        public static function getCart() <br />
        {<br />
        if(!isset($_SESSION['cart']) || !($_SESSION['cart'] instanceof self)) <br />
        {<br />
            echo '1';<br />
            $_SESSION['cart'] = self::getIns();<br />
        }<br />
<br />
        return $_SESSION['cart'];<br />
    }<br />
<br />
Copy after login


这是我的购物车类(部分),我在页面直接引用它使用不会出现任何问题,但是在有一将它放入一序列的初始化类中在引用它的时候就会产生了一个问题,每次它都会重新生成过,就没有了单例的效果。不知道我的问题描述清楚了没有,请各位高手给小弟一点建议或者思路,有可能哪里出问题了???

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template