can i save a class into a session and read it back on another page?
thnaks in advance
peleg
sessions and classes
Moderator: General Moderators
you can, the best way is to use references: onLAMP Article and PHP Manual: references.
Why references instead of passing entire classes? References offer a cleaner and far less resource-hungry way of doing the same thing
Why references instead of passing entire classes? References offer a cleaner and far less resource-hungry way of doing the same thing
how i do it:
Code: Select all
session_start();
include('class.ShoppingCart.php');
$ShoppingCart =& $_SESSION['ShoppingCart'];
if (!is_object($ShoppingCart)) {
$ShoppingCart = new ShoppingCart();
}I would add an ampersand & before you instantiate that class:
Code: Select all
session_start();
include('class.ShoppingCart.php');
$ShoppingCart =& $_SESSION['ShoppingCart'];
if (!is_object($ShoppingCart)) {
$ShoppingCart =& new ShoppingCart();
}