Php uses serialize () and unserialize () to convert objects into super variables.

Source: Internet
Author: User
Php uses serialize () and unserialize () to make the object into the original words and some summary in the Super variable Manual: php function serialize () and unserialize () Description and case. To change serialized strings back to PHP & #20540;, use unserialize (). Serialize () can be processed in addition to re php using serialize () and unserialize () to make the object into a super variable.

The original words and summary in the manual:

Description and case of php functions serialize () and unserialize. To change serialized strings back to PHP values, use unserialize (). Serialize () can process any type other than resource. Even serialize () contains arrays that point to its own reference. References in arrays/objects of serialize () will also be stored.

Serialize () returns a string that contains a byte stream that represents value and can be stored anywhere. This facilitates storing or passing PHP values without losing their types and structures.

To change serialized strings back to PHP values, use unserialize (). Serialize () can process any type other than resource. Even serialize () contains arrays that point to its own reference. References in arrays/objects of serialize () will also be stored.

When an object is serialized, PHP tries to call the member function _ sleep () of the object before the sequential action (). This allows objects to be cleared before being serialized. Similarly, when you useUnserialize ()When the object is restored, the _ wakeup () member function is called.

Note: in PHP 3, object attributes will be serialized, but methods will be lost. PHP 4 breaks this restriction and can store attributes and methods at the same time. For more information, see the serialization object section of the class and object.

Serialize () and unserialize () are described in the php manual as follows:

Serialize-Generates a storable representation of a value

Serialize-generate a representation of a stored value

Unserialize-Creates a PHP value from a stored representation

Unserialize-Create a PHP value from a stored representation

Serialize, Translated as "serialization, continuous", usually called"Serialization"

This function is useful, especially when used with unserialize.

I think it is useful to store data in a database or record it in a file.

Of course, this type of data must be complex (neither complicated nor serialize is required, and I think at least it must be an array) and be non-"index or primary key" in the database ", of course, it is best to leave this database field irrelevant to any search program in the system. of course, the data after serialize can still be searched because the specific data is not encrypted or changed.


Instance: (it is easy to talk about objects only)

CPerson. php

 age=$age;    }    function walk()    {        echo "I'm walking...!";    }}?>

Test0.php saves the object here

 

Test1.php access object

 walk();echo $a->age;?>



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.