PHP? Interface-serializable Interface

Source: Internet
Author: User
Interface Summary:

1 Serializable  {2     3     /* Method */4 Abstract public string     serialize  (void)//object string representation 5     Abstract Public mixed Unserialize  (string $serialized  )//Construct object 6     7}    

It is very simple to use, as long as the Serialize method is called when serializing the object, and when deserializing, the Unserialize method is called.

Example:

Class Ser implements Serializable {    private $_data = null;    Public function __construct (array $data = null) {        $this->_data = $data;    }    Public Function serialize () {        echo ' is serializing
'; $data = $this->_data; Return serialize ($DATA); } Public Function Unserialize ($data) { echo ' is deserializing
'; $_data = Unserialize ($data); $this->_data = $_data; } Public Function Get_data () { return $this->_data; }} $d 1 = Array (' a ' = = ' A ', ' B ' = ' B '), $t 1 = new Ser ($d 1); $s 1 = serialize ($t 1);//serialization
$o 1 = unserialize ($s 1);//deserializing

Purpose: In the serialization of the image?? Using the Serialize method in the elephant,?? Daniel??。 In the deserialization of?? Using the Unserialize method in the elephant,?? Daniel??。
Can be used in model??? Seal up.

  • 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.