Click to See Complete Forum and Search --> : Serializing an Object


beverage
06-12-2008, 09:51 AM
I'm hoping that someone out there maybe able to provide me with a quick answer to this problem - before I start banging my head against a brick wall!!!

Basically, I have a rather large object which is being serialized before being stored in a database.

This object is made up of several other objects, of which they are made up of objects and so on... Within one of these inner objects there is a property called 'key' which has a numeric value assigned to it.

I've discovered that when I serialize it, and then unserialize it and look at the unserialized object, the value for the 'key' property is not there.

It would appear that the value for the 'key' property is not being serialized it. I'm wondering if anyone has come across this before and if anyone has any hints or tips to get around the problem??

Thanks,

Bev

MrCoder
06-12-2008, 09:59 AM
Just throwing something out there, is it scope related?
I'm not sure if serialize takes scope in to account, but is "key" a private / protected variable?

beverage
06-12-2008, 10:08 AM
Good point, and one of my colleagues suggested that to me.

Key is set as a protected variable along with several others. So I've tried setting key to be both a public variable, and just the default variable and still get the same problem when I tried both ways.

What I wondered is if key is a keyword with the serialize and unserialize function??

Thanks for the suggestion though :)

MrCoder
06-12-2008, 10:13 AM
Since "key" is a function used on arrays and serialize is based on an array like structure then it is a possibility..

Try echoing "key" within the __sleep() function of the class at the point of being serialized?
Is the value of key stored in the textual data created by serialize? (Is it unserialize causing the issue)

beverage
06-12-2008, 10:31 AM
Is the value of key stored in the textual data created by serialize? (Is it unserialize causing the issue)

Ahh Ha - once the object has been serialized and I view it - key is no longer present, so not unserialize causing the problem but serialize...

I'll try and figure out which __sleep function is being used and echo out 'key', I have the feeling that the problem is something to do with __sleep but not really got my head round __sleep and __wakeup yet!!!

Cheers for the point in the right direction :)