The serialization and drag of PHP object-oriented detailed objects

Source: Internet
Author: User

The seventh chapter (11) Object-oriented detailed object serialization and drag
Serialization is the conversion of an object into a binary string (the name of the object to be serialized).
Drag is the binary word into Object unserilize (to drag the object name of the row).
Serial Serialization Criteria:
$r 1=new Ren ("John", 20, "male");
$str = ($r 1< object to serialize >);
$file =fopen ("Tmp.txt" < serialization saved to the file address, "W" < write >);
Fwrite ($file, $STR);
Fclose ($file);
Drag standard of the line:
Include "ren.php" < move a serialized object's PHP into drag-formatted PHP >;
$file =fopen ("Tmp.txt" < to drag the document address of the row, "R" < read >);
$str =fread ($file, FileSize ("Tmp.txt" < read the length of the file address is a good length of the file to attend >));
Fclose ($file);
$r =unserilize ($STR);
$r->shuohua ();
Under what circumstances will the object be serialized:
1. When the object is transmitted in the network.
2. When the object is stored in a file or database.
__sleep () {$arr =array (attributes to be serialized); return $arr;} The method that is invoked automatically when a partial property is serialized.
__wakeup () Drag the method that is invoked automatically when the line is in use < can initialize the serialized property at drag.
The seventh chapter (12) object-oriented Detailed _ abstract method and abstract class
Abstract method: The method in which there is no method body in a class is an abstract method.
abstract< Abstract Method keyword > function method name ();.
Abstract class: An abstract class cannot instantiate an object, this class is an abstract class, and an abstract class cannot instantiate an object, and it needs to be decorated with an abstract before this class.
The purpose of the abstract class: the equivalent of a specification, if you want to abstract the original function in the class of the implementation must be an abstract class as the parent class to do a subclass, and then cover the complete abstract class inside the abstract methods in order to make the function of the abstract class implemented.

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.