Open the p1.text file and enter the content: O:6:"Person":2:{s:12:" Person name";s:4:"Zhang San";s:11:" Person age";i:20;} But usually the characters generated by the above serialization are not directly parsed. Second, deserialization:
output result: My name is: Zhang San My age is: 20 Tip: Since a serialized object cannot serialize its methods, when unserialize, the current file must contain the corresponding class or require the corresponding class file. Serialization can only be used with limited users, because files need to be stored or written separately for each user, and the file name must not be repeated. In the case where the user cannot exit the browser normally, there is no guarantee that the file will be deleted. The object is registered as a session variable. When there are a large number of users, you can consider using session to save objects. For more information about session, please see the article: Simple example of session in php php session operation class (with examples) php session function set Detailed explanation of session expiration setting method in php Examples of session application in php Session usage examples of php session technology php log out session information Cookie and Session usage in php5 Example:
Read session:
Output results: My name is: Zhang San My age is: 20 Like serialization, registering an object as a session variable does not save its methods. Therefore, when reading session variables, the current file must contain the corresponding class or require the corresponding class file. |