Php serialization and deserialization, php serialization and serialization

Source: Internet
Author: User

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 "

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.