I was wondering if anyone could point me to a resource where the details of a serialized php string is documented. I would basically like to know the format/structure so I c
The basic structure is as follows:
Scalar types:
Booleans are serialized as:
b:;
where is an integer with a value of either 0 (false) or 1 (true).
Integers are serialized as:
i:;
where is the integer value.
Floats are serialized as (with d meaning double):
d:;
where is the float value.
Strings are serialized as:
s::"";
where is an integer representing the string length of , and is the string value.
Special types:
null is simply serialized as:
N;
Compound types:
Arrays are serialized as:
a::{}
where is an integer representing the number of elements in the array, and zero or more serialized key value pairs:
where represents a serialized scalar type, and any value that is serializable.
Objects are serialized as:
O::""::{}
where the first is an integer representing the string length of , and is the fully qualified class name (class name prepended with full namespace). The second is an integer representing the number of object properties. are zero or more serialized name value pairs:
where is a serialized string representing the property name, and any value that is serializable.
There's a catch with though:
is represented as
s::"";
where is an integer representing the string length of . But the values of differs per visibility of properties:
a. With public properties is the simple name of the property.
b. With protected properties, however, is the simple name of the property, prepended with \0*\0 — an asterix, enclosed in two NUL characters (i.e. chr(0)).
c. And with private properties, is the simple name of the property, prepended with \0 — \0, enclosed in two NUL characters, where is the fully qualified class name.
There are a few other cases, such as R:;, that represents references, that I haven't mentioned here (because I honestly haven't figured out the exact workings of it yet), but this should give you a decent idea about PHP's serializing mechanism.