Going nuts over an object in a session weirdness:
(php 4.3.2 xpPro apache register_globals=off)
I have an object (cart) which i store in a session.
I have included the class definition on the page BEFORE session_start();
The class itself is solid and if the object is not included in a session works just fine.
When it is registered in a session if responds well the first 2 times the addToCart() method is invoked and then--------- it looses state.
The inner counters of the object remain stuck and it keeps replacing the last (second) item in the cart with the new one i want to add.
Again i state that the class is solid and preforms well if the object isn't stored in a session, but the class file has been attached to this post just in case.
Here's the (simplified) code:
<?php
include 'cartClass.php';
session_start();
$sesVars=$HTTP_SESSION_VARS;
$getVars=$HTTP_GET_VARS;
$action=$getVars['action'];
$prod=$getVars['prod'];
$cart=$sesVars['cart'];
if($action=='addToCart'){
if(!$cart){
$cart=new Cart();
session_register('cart');
}
$cart->addToCart($prod);
}
echo('
<a href=\'a.php?prod=pr1&action=addToCart\'>product1</a><br>
<a href=\'a.php?prod=pr2&action=addToCart\'>product2</a><br>
<a href=\'a.php?prod=pr3&action=addToCart\'>product3</a><br>');
?>