require_once('includes/cart.php');
session_start();
methods are not stored within session
Paul wrote:
Hi All:
I have a simple page that checks for existence of object in a session.
If the object is not stored in session object, it creates new one:
If (isset ($_SESSION["cart"])) {
$cart=$_SESSION["cart"];
} else {
$cart = new ShoppingCart ();
$_SESSION["cart"]= $cart;
}
So the object cart is available in every page. At this point the cart is
a simple class:
class ShoppingCart {
var $items = array();
function AddItem ($item){
if ($this->items[$item]) {
$this->items[$item]=$this->items[$item]+1;
} else { $this->items[$item]=1;
}
} // additem
}
So the cart is either retrieved from the session or created (if non
existent), however, every time the script calls :
$cart->AddItem($_GET['item_id']);
I get the following error:
Fatal error: The script tried to execute a method or access a property
of an incomplete object. Please ensure that the class definition
shoppingcart of the object you are trying to operate on was loaded
_before_ the session was started in .... on line 59
Where line 59 is pointing to $cart->AddItem($_GET['item_id'])
Session_start is present in every page.
Could anyone help me understand where the problem is?
Thanks
Paul
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php