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.