Stats

299 Contributors: 8 Wednesday, January 4, 2017
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial: riptutorial@gmail.com
Roadmap: roadmap

Serialization

Syntax

  • string serialize ( mixed $value )

Parameters

ParameterDetails
valueThe value to be serialized. serialize() handles all types, except the resource-type. You can even serialize() arrays that contain references to itself. Circular references inside the array/object you are serializing will also be stored. Any other reference will be lost. When serializing objects, PHP will attempt to call the member function __sleep() prior to serialization. This is to allow the object to do any last minute clean-up, etc. prior to being serialized. Likewise, when the object is restored using unserialize() the __wakeup() member function is called. Object's private members have the class name prepended to the member name; protected members have a '*' prepended to the member name. These prepended values have null bytes on either side.

Remarks

Serialization uses following string structures:

[..] are placeholders.

TypeStructure
Strings:[size of string]:[value]
Integeri:[value]
Doubled:[value]
Booleanb:[value (true = 1 and false = 0)]
NullN
ObjectO:[object name size]:[object name]:[object size]:{[property name string definition]:[property value definition];(repeated for each property)}
Arraya:[size of array]:{[key definition];[value definition];(repeated for each key value pair)}

Related Examples