6.13. Object Serialization
The serialize function, discussed in Chapter 15, converts variables, including objects, into strings. You can store the serialized variable in a file or send it across the network. Afterwards, unserialize can convert the string back into the appropriate value. As long as you define a class prior to unserializing an object of that class, PHP can successfully restore the object's properties and methods. In some situations you may need to prepare an object prior to serialization and likewise perform some procedure immediately after unserialization. For these purposes, PHP looks for the __sleep and __wakeup methods.
When serializing an object, PHP calls the __sleep method if it exists. After unserializing an object, PHP ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access