Serialization is the conversion of variable data to a string (unlike a type conversion mechanism), which is typically used to store data (files) and then recover in other cases (deserialization)
Serialization:
$val = serialize($var);file_put_contents('./*.txt',$val);
Deserialization:
$val = file_get_contents('./*.txt');$var = unserialize($val);
When an object is serialized, __sleep () in the class is called automatically;
When deserializing an object, the corresponding class's __wakeup () is automatically called, and the corresponding class declaration must be in the inverse sequence operation.
__sleep () can perform cleanup of some data (resources), and returns an array that stores the properties of objects that need to be serialized, that is, the properties can be picked for serialization.
classbee{public$a; protected$b; private$c; publicfunction__sleep(){returnarray('a','b'); }}
__wakeup () perform some useful ' data recovery work ', such as connecting to a database, when doing a deserialization session
publicfunction__wakeup(){$this->func();}
__tostring ()
This method is called automatically when an object is treated as a string. This method allows you to return the appropriate string, which would be an error if the method is not defined.
classbee{publicfunction__tostring(){echo'string'; }}$objnew bee();//对象不能直接当字符串使用echo$obj;
__invoke ()
This method is called automatically when the object is used as a method
classbee{publicfunction__invoke(){echo'invoke'; }}$objnew bee();//对象不能直接当字符串使用echo$obj();
'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
'). Text (i)); }; $numbering. FadeIn (1700); }); });
The above describes the PHP serialization, including aspects of the content, I hope the PHP tutorial interested in a friend to help.