Wow thats strange?? I am using PHP 4.3.2 as well and I don't see that happening where it serializes the object when assigning it to the $_SESSION. I am using the dbg debugger and nusphere PHP editor and I can step through the code and as I do it shows that the session var is not serialized. However when I checked the session data in the /tmp directorie it appears to serialized
It could be that my version of PHP doesn't match the dbg version and dbg reporting back false information (which I have to look into that). Also I checked my ini settings and it shows the session.serialize_handler = php which should be default.
Another thing is that I didn't come accross in my reading of http://www.php.net/manual/en/language.oop.serialization.php where it says that objects assigned to the global $_SESSION var is automatically serialized. I did see that if you use the session_register() function it automatically serializes but again I'd like to avoid that.
Right now it seems I have many unkowns, so i'm going to narrow them down ....
Matt
Mike Migurski wrote:
$customer = new Customer($_GET['facilityID'], $_GET['customerID']); $_SESSION['acceptPayment']['serializedCustomer'] = serialize($customer);
so now when I have moved on to another page or another instance of the same page and I want to access the object from the session var, I do so like this:
$customer = unserialize($_SESSION['acceptPayment']['serializedCustomer']);
and now you can access the object. There is a hidden jewl about this method, I now no longer have to include or require the class file because it is already defined in the serialized string.
Really, you don't need the serialize/unserialize in there, as they are handled automagically. $_SESSION['customer'] = $customer; and $customer = $_SESSION['customer'] should work just fine. I'm doing this with 4.3.2, and a casual glance at my sess_* files in /tmp shows that the objects are stored in serialized form and the __sleep() method is called the usual way.
My understanding is that classes must be defined prior to unserializing an object if you dan't want to risk having the object becoming disassociated from its class, but your method above does have the advantage that you decide when that serialization takes places and can load the classes there, rather than having to do so prior to session_start().
http://www.php.net/manual/en/language.oop.serialization.php
--------------------------------------------------------------------- michal migurski- contact info and pgp key: sf/ca http://mike.teczno.com/contact.html
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php