PHP serialization format explained

The PHP serialization format is the serialization format used by the PHP programming language. The format can serialize PHP's primitive and compound types, and also properly serializes references.[1] The format was first introduced in PHP 4.[2]

In addition to PHP, the format is also used by some third-party applications that are often integrated with PHP applications, for example by Lucene/Solr.[3]

Syntax

The syntax generally follows the pattern of one-letter code of the variable type, followed by a colon and the length of the data, followed by the variable value, and ending with a semicolon.

TypeSerialization examples
NullN;
Booleanb:1;
b:0;
Integeri:685230;
i:-685230;
Floating pointd:685230.15;
d:INF;
d:-INF;
d:NAN;
Strings:5:"apple";
s:6:"A to Z";
Associative arraya:4:{i:0;b:1;i:1;N;i:2;d:-421000000;i:3;s:6:"A to Z";}
<nowiki>a:2:{i:42;b:1;s:6:"A to Z";a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}}</nowiki>
ObjectO:8:"stdClass":2:{s:4:"John";d:3.14;s:4:"Jane";d:2.718;}

External links

Notes and References

  1. Web site: Serialization. 2020-07-05. PHP Internals Book.
  2. Web site: PHP: serialize - Manual. 2020-07-05. PHP: Hypertext Preprocessor.
  3. Web site: Response Writers Apache Solr Reference Guide 8.5 . 2020-07-05 . lucene.apache.org.