Php serialization and deserialization, php serialization and serialization
Php serialization & deserialization is very useful for compression and read/write operations on some large files.
A simple serialization case
Serialization and deserialization functions are used at the same time. When the two functions are called, they will respectively call the corresponding functions __sleep and _ wakeup.
<? Php/* _ sleep and _ wakeup exercises: story: A fruit farmer produces many fruit types, so he needs to send a specified category to the buyer, date of production and date sent to the buyer for the fruit category (several Members, Apple Type, Sydney type, watermelon type) ------------------------ fruit. class. php (_ sleep and _ wakeup) buy. phppass. php
//////// All three files are written in index at the same time. */class Fruit {private $ apple; private $ banana; private $ xigua; private $ xuanli; private $ date; function _ construct ($ apple, $ banana, $ xigua, $ xueli, $ date = "1.26") {$ this-> apple = $ apple; $ this-> banana = $ banana; $ this-> xigua = $ xigua; $ this-> xueli = $ xueli; $ this-> date = $ date;} function getInfo () {echo "information :". $ this-> apple. "&&&". $ this-> banana. "&&&". $ this-> xigua. "&&&". $ this-> xueli. "<br/> production date ". "&&&". $ this-> date;} function _ sleep () {$ info = array ("apple", "xueli", "xigua", "date "); return $ info;} function _ wakeup () {$ this-> date = "2.20" ;}/// 1 // $ fruit = new Fruit ("apple ", "banana", "watermelon", "Sydney"); // $ fruit-> getInfo (); // 2 echo "<br/> fruit: <br/> "; $ fruit = new Fruit (" apple "," banana "," watermelon "," Sydney "); $ str = serialize ($ fruit ); $ fruit-> comment ', $ str); echo "