Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Initializing class in a session

Status
Not open for further replies.

DeepBlerg

Technical User
Jan 13, 2001
224
AU
I have initialized a class in a session like so on products.php:

require_once("classes/shopping_cart.class.php");
$cCart = new shopping_cart();
session_register("cCart");


On cart.php I retrieve the cart like so:

$scCart =& $_SESSION["cCart"];

However, if I call:

$scCart->addProduct($ProductID);

I get this message:
Fatal error: Call to a member function on a non-object

Even if I call the session directly like:

$_SESSION["cCart"]->addProduct($ProductID);

Still get the same error, any ideas?
 
sholdn this be:
$scCart =& $_SESSION("cCart");

Known is handfull, Unknown is worldfull
 
its actually

$scCart =& $_SESSION["cCart"];

but this forum processed the square brackets
 
o.k:
did u do that?
$scCart =& $_SESSION["cCart"];

and what happens when u create the object file directly in that php page?


Known is handfull, Unknown is worldfull
 
Instead of assigning an additional variable a reference to $_SESSION['cCart'], have you first tried simply:

$_SESSION['cCart']->addProduct(...);

?

Have you tried performing the assignment to the additional variable, then performing:

print_r ($scCart);

to verify your variable?


Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top