Let's try this again.
I am having a problem with a small shopping cart I am creating as a vehicle for learning more about shopping carts and sessions.
I have the following script: addtocart.html
<?php
session_start();
require_once('myClasses.php'); // holds classes cart and item
if ( !session_is_registered('cart') ){
$cart = new Cart();
session_register('cart');
}
$cart->showCart();
// ... more code not displayed - to save space...
?>
The code above is what is giving me 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 cart of the object you are trying to operate on was loaded before the session was started
I have a products page with two items on it. Each item is in it's own form who's action calls this addtocart.html script. addtocart.html is the first page with any session stuff on it.
A couple of questions:
- What is causing this error? I understand classes and oop, and a bit about sessions, so I'm guessing my $cart object is not being recognized. The first time through the code there should be no session_registered('cart'). So, $cart = new Cart(); should get created.
The next time through the script, session_registered('cart') should be seen so the $cart object should not get created again, right?
- What is the connection, if any, between session_registered('cart') and $cart? I do not understand how the cart variable is associated with the $cart object.
Thanks in advance if anyone can clear this up for me.
johnc