PHP Serialization

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!


  • string serialize ( mixed $value )


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.


Serialization uses following string structures:

[..] are placeholders.

Strings:[size of string]:[value]
Booleanb:[value (true = 1 and false = 0)]
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)}

Got any PHP Question?