The Horde_Serialize library provides various methods of encapsulating data.