note 31542 added to language.oop.serialization
| From: | mike at nostupidspam dot lenyon dot com | Date: | Fri, 25 Apr 2003 12:30:26 +0000 |
| Subject: | note 31542 added to language.oop.serialization | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-47075@lists.php.net to get a copy of this message | ||
i'm still having a problem retrieving an object stored in the session. on one page, i
instantiate and store my shoppingCart object in the session. on another page i start the session
and try to retrieve that object. it unserializes with mixed results: i can call the methods of the
object, but the cart contains no items.
to illustrate:
................PAGE 1................
// general.php includes a file that declares shoppingCart
require ("includes/functions/general.php");
session_start();
if (!session_is_registered("cart")) {
$cart = new shoppingCart;
session_register("cart");
}
// add/remove/modify items in cart
// list items in cart
// count items in cart
// all working on each visit to page
................PAGE 2................
// general.php includes a file that declares shoppingCart
require ("includes/functions/general.php");
session_start();
if (session_is_registered("cart")) {
$products = $cart->get_products();
// always shows zero on this page and
// the correct number on PAGE 1
echo "<script>alert('" . sizeof($products) .
"')</script>";
}
--
http://www.php.net/manual/en/language.oop.serialization.php
http://master.php.net/manage/user-notes.php?action=edit+31542
http://master.php.net/manage/user-notes.php?action=delete+31542
http://master.php.net/manage/user-notes.php?action=reject+31542