__PHP_Incomplete_Class Object even though class is included before session started

1.8k views Asked by At

I have a "page" class that on it's construct includes a "shoppingCart" class, starts a session, creates a shoppingCart object, and then sets $_SESSION['shoppingCart'] to the shoppingCart object.

I still get an incomplete class when I print_r the session...

I thought this only happens when you start the session before including the class?

The code in my "page" class looks like this:

include ('include/shopping_cart.php');

if (session_id() == '')
    {
    session_start();
    }

if (!isset($_SESSION['shoppingCart']))
    {
    $_SESSION['shoppingCart'] = new shoppingCart;
    }

I obviously don't understand this... Please help!

1

There are 1 answers

0
user3640967 On BEST ANSWER

To store an object in a session two things must happen:

1) The class must be defined before the session is started. 2) The class must implement serializable.