hemant_419
12-01-2003, 07:47 AM
Please help immediately
First time this is working
and second time not
-----------------------------
page name = shop/products.php
<?
session_start();
include_once("shop_cart.php");
$my_cart = new shop_cart();
if( isset($_SESSION['user_cart']) )
{
$my_cart = $_SESSION['user_cart'];
$my_cart->push();
}
else
{
$val = $my_cart->push();
echo "<br>Return Value: $val<br>";
}
$_SESSION['user_cart'] = $my_cart;
echo "index: " . $_SESSION['user_cart']->index;
?>
----------------------------
----------------------------
page name = shop/shop_cart.php
<?
class shop_cart
{
var $index = 0;
function push()
{
$this->index = $this->index + 1;
return $this->index;
}
}
?>
---------------------------
Error:-
Fatal error: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition shop_cart of the object you are trying to operate on was loaded _before_ the session was started in C:\indigoperl\apache\htdocs\shop\haveProducts_include.php on line 9
Err description:
Save first code as shop/file1.php
Other as shop/shop_cart.php
open browser and type
http://localhost/shop/first.php
This will work fine
Now the problem comes
Just refresh that window and see results
First time this is working
and second time not
-----------------------------
page name = shop/products.php
<?
session_start();
include_once("shop_cart.php");
$my_cart = new shop_cart();
if( isset($_SESSION['user_cart']) )
{
$my_cart = $_SESSION['user_cart'];
$my_cart->push();
}
else
{
$val = $my_cart->push();
echo "<br>Return Value: $val<br>";
}
$_SESSION['user_cart'] = $my_cart;
echo "index: " . $_SESSION['user_cart']->index;
?>
----------------------------
----------------------------
page name = shop/shop_cart.php
<?
class shop_cart
{
var $index = 0;
function push()
{
$this->index = $this->index + 1;
return $this->index;
}
}
?>
---------------------------
Error:-
Fatal error: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition shop_cart of the object you are trying to operate on was loaded _before_ the session was started in C:\indigoperl\apache\htdocs\shop\haveProducts_include.php on line 9
Err description:
Save first code as shop/file1.php
Other as shop/shop_cart.php
open browser and type
http://localhost/shop/first.php
This will work fine
Now the problem comes
Just refresh that window and see results