[PHP] RE: Problem with Class - incomplete object error

2002-11-18 Thread Tim Ward
you've included the class definition at the top of every page, right?

and why don't you just use $_SESSION[cart] directly instead of using
$cart?
that way you don't have to worry about scoping issues and continually
passing $cart through to functions.

Tim

 -Original Message-
 From: Paul [mailto:[EMAIL PROTECTED]]
 Sent: 18 November 2002 02:59
 To: [EMAIL PROTECTED]
 Subject: Problem with Class - incomplete object error
 
 
 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




RE: [PHP] RE: Problem with Class - incomplete object error

2002-11-18 Thread Paul
Yes, I have included class definition on the top of the page.

The reason that was using $cart is the fact that I was calling
methods/functions of the object such as $cart-AddItem()..and I was not
sure whether $_Session['cart']-AddItem would be a correct way or not

Paul

-Original Message-
From: Tim Ward [mailto:[EMAIL PROTECTED]] 
Sent: Monday, November 18, 2002 4:17 AM
To: 'Paul'; [EMAIL PROTECTED]
Subject: [PHP] RE: Problem with Class - incomplete object error

you've included the class definition at the top of every page, right?

and why don't you just use $_SESSION[cart] directly instead of using
$cart?
that way you don't have to worry about scoping issues and continually
passing $cart through to functions.

Tim

 -Original Message-
 From: Paul [mailto:[EMAIL PROTECTED]]
 Sent: 18 November 2002 02:59
 To: [EMAIL PROTECTED]
 Subject: Problem with Class - incomplete object error
 
 
 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




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] RE: Problem with Class - incomplete object error

2002-11-18 Thread Ford, Mike [LSS]
 -Original Message-
 From: Paul [mailto:[EMAIL PROTECTED]]
 Sent: 18 November 2002 11:49
 To: 'Tim Ward'; [EMAIL PROTECTED]
 Subject: RE: [PHP] RE: Problem with Class - incomplete object error
 
 
 Yes, I have included class definition on the top of the page.

And are you 100% sure it's before your session_start()?

 
 The reason that was using $cart is the fact that I was calling
 methods/functions of the object such as $cart-AddItem()..and 
 I was not
 sure whether $_Session['cart']-AddItem would be a correct way or not

Well, no, but $_SESSION['cart']-AddItem would...;)!

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php