Serialize it:
$str = serialize($object);
If your object contains private / protected fields, it is also a good idea for base64_encode() serialized object, since these properties will lead to the use of ascii-1 characters, which will break when editing a column manually, for example. with phpMyAdmin ..
To restore your object, you simply unserialize() string ( base64_decode() before that, if necessary).
Thiefmaster
source share