For those who have just touchedPHP (starting with PHP 3.05) provides a set of serialized and deserialized functions for saving objects: Serialize, Unserialize. However, the description of the two functions in the PHP manual is limited to how they are used, and the format of the serialized results is not described.
Therefore, this is more cumbersome for implementing the PHP serialization format in other languages. Although some other languages have been compiled to implement the PHP serialization program, but these implementations are not complete, when the serialization or deserialization of some more complex objects, there will be an error.
So I decided to write a document about the details of the PHP serialization format (that is, this document) so that I could have a more complete reference when writing PHP serializers implemented in other languages.
What I wrote in this article is that I have written a program to test and read the PHP source code, so I can't 100% guarantee that everything is correct, but I will try my best to ensure the correctness of what I have written, and I will make it clear in the text that I am not quite sure. We also hope that we can supplement and perfect it.
PHP serialized format is a simple text format, but the letter case and whitespace (space, carriage return, newline, etc.) sensitive, and the string is calculated by byte (or 8-bit characters), so it is more appropriate to say that the content of PHP serialization is the byte stream format.
Therefore, when implemented in other languages, if the string in the implemented language is not a byte storage format, but rather a Unicode storage format, the serialized content is not suitable to be saved as a string, but should be saved as a byte stream object or an array of bytes, otherwise the data exchange with PHP will produce an error.
PHP uses different letters to mark different types of data, and the use of serialized PHP with Yahoo! Web Services provides all the letters and their meanings in the Yahoo development site:
A-array
B-boolean
D-double
I-integer
O-common Object
R-reference
S-string
C-custom Object
O-class
N-null
R-pointer Reference
U-unicode string
N represents NULL, while B, D, I, and s represent four scalar types, and the PHP serialization formatter currently implemented by other languages basically implements serialization and deserialization of these types, although there are problems with implementations of s (strings).
A, O is the most commonly used composite type, most of the other language implementations are well implemented for the serialization and deserialization of a, but to O only implemented the PHP4 in the object serialization format, but did not provide support for the extended object serialization format in PHP 5.
R, R, which represent both object references and pointer references, are also useful in serializing complex arrays and objects that produce data with these two markers, which we will explain in detail later, which are not yet found in other languages.
C is introduced in PHP5, which represents a custom object serialization method, although this is not necessary for other languages because it is seldom used, but it is explained in detail later.
U is introduced in PHP6, which represents a Unicode encoded string. Because PHP6 provides the ability to save strings in Unicode, it provides the format of this PHP serialization format string, although this type is not supported by PHP5, PHP4, and these two versions are currently mainstream, so it is not recommended to serialize this type when implemented in other languages, However, it is possible to implement its deserialization process. I'll also explain the format of it later.
And finally there's an O, which is the only one I haven't figured out yet. A data type indicator. This indicator was introduced in PHP3 to serialize objects, but was replaced by O after PHP4. In the source code of PHP3, you can see that the serialization and deserialization of O is essentially the same as array A. But in the source code of PHP4, PHP5, and PHP6, the PHP serialization format is missing its shadow, but there are several versions of the Deserializer source that deal with it, but I haven't figured out what to do with it. So there is no more explanation for it for the time being.
http://www.bkjia.com/PHPjc/446212.html www.bkjia.com true http://www.bkjia.com/PHPjc/446212.html techarticle For those that have just touched PHP (starting with PHP 3.05), provide a set of serialization and deserialization functions for saving objects: Serialize, Unserialize. In the PHP manual, however, the two letters ...