Problem with Class - incomplete object error
| From: | Paul | Date: | Mon, 18 Nov 2002 02:59:25 +0000 |
| Subject: | Problem with Class - incomplete object error | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-124858@lists.php.net to get a copy of this message | ||
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