The php Function Serialize
The php function serialize is used to convert any value into its storable representation in string format. This is useful for storing and passing around PHP values without losing their type and structure. To turn the string back into the original PHP value, use unserialize().
Objects and arrays in PHP are complex data structures that aren’t really designed to be transported outside of a running script. To enable them to be moved between different systems, they must be made serializable. Serialization is the process of turning a data structure into a string of byte-streams that can be read and processed by other programs.
The PHP serialize() function turns an array, object, or any other complex data structure into a string that can be stored in a database, passed to another script, or sent as part of an HTTP request. It also allows for circular references within an object to be saved as they are serialized.
This is very useful for moving complex data between different systems, as the data can be transferred as a single string. In order to make it work, however, the data must be properly encapsulated in an object.
Fortunately, PHP has two hooks that can be called during the serialization and unserialization processes. The _ _sleep() and _ _wakeup() methods provide a way to make an object aware of the fact that it’s going to be serialized. If an object doesn’t have these methods, it won’t get notified and will lose its shape during the serialization process.