Questions about phpsession shopping cart

Source: Internet
Author: User
Class & nbsp; CartTool & nbsp; & nbsp ;{& nbsp; & nbsp; & nbsp; private & nbsp; static & nbsp php session shopping cart problems

Class CartTool
{
Private static $ ins;
Private $ good = array ();

Final private function _ construct ()
{

}
Final private function _ clone ()
{

}

// Obtain the instance
Protected static function getIns ()
{
If (! (Self: $ ins instanceof self ))
{
Self: $ ins = new self ();
}

Return self: $ ins;
}


/**
* Function: put the singleton object of the shopping cart in the session.
*
*
* @ Return instance Singleton object of the shopping cart
**/
Public static function getCart ()
{
If (! Isset ($ _ SESSION ['cart']) |! ($ _ SESSION ['cart'] instanceof self ))
{
Echo '1 ';
$ _ SESSION ['cart'] = self: getIns ();
}

Return $ _ SESSION ['cart'];
}



This is my shopping cart class (part). I reference it directly on the page without any problems, however, when you reference it in the initialization class of a sequence, a problem occurs. every time it is re-generated, the effect of a singleton is no longer displayed. I don't know if my problem is clearly described. please give me some suggestions or ideas. what may happen ??? Share:
------ Solution --------------------
We recommend that you use another method.
Use session id or a cookie variable as a flag.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.