O'Reilly logo

Core PHP Programming, Third Edition by Leon Atkinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required