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.