troubleshooting Question

PHP incomplete object

Avatar of jonlondon12
jonlondon12 asked on
PHP
10 Comments1 Solution3232 ViewsLast Modified:
hi,

I am trying declaring some classes like so, and making a ShoppingCart class in a $_SESSION[], like so:

<?php
      ini_set("include_path", "../../includes/");
      session_write_close();
      //require_once("classes/User.inc.php");
      require_once("classes/User.inc.php");
      require_once("classes/Link.inc.php");
      require_once("classes/Page.inc.php");
      require_once("classes/Product.inc.php");
      require_once("classes/ProductCategory.inc.php");
      require_once("classes/ewizDatabase.inc.php");
      require_once("classes/OutputFunctions.inc.php");
      require_once("classes/SectionAddition.inc.php");
      require_once("classes/ShoppingCart.inc.php");
      session_start();

      if(!(isset($_SESSION['cart']))){
            $cart = new ShoppingCart();
            $_SESSION['cart']=$cart;
      }
?>

when I try and call a method of the class, like so:

                 $_SESSION['cart']->outputMainCart();

I get the following error:

Fatal error: main() [function.main]: 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_ unserialize() gets called or provide a __autoload() function to load the class definition in C:\Program Files\xampp\htdocs\ewizadm\sites\b1477235\index.php on line 166

Please Help!!!

The ShoppingCart class is looks like this:


<?
require_once("Product.inc.php");

class ShoppingCart{
      
      
      private $vatRate=17.5;
      private $products;
      private $totalPrice;
      private $totalVAT;
      

      function addProduct($prodName){
            //add the image to the array
            $product = new Product();
            $product->getProductFromDB($prodName);
            $this->products[]=$product;

            $this->totalPrice+=$product->getPrice();
      }
      
      function getProduct($index){
            //add the image to the array
            return $this->products[$index];
      }
      
      function getPriceWithoutVAT(){
            return $totalPrice * (100 - $this->vatRate);
      }

      function getTotalVAT(){
            return $totalPrice * $this->vatRate;
      }      

      function getTotalPrice(){
            return $totalPrice;
      }
      
      function outputSideCart(){
            echo "cool";
      }
      
      function outputMainCart(){
      
      }

}

?>

Thanks for looking
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros