In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What is PHP serialization? in order to solve this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
We all know that PHP serialization can convert variables including objects into continuous bytes data. You can store serialized variables in a file or transfer them on the network, and then restore the serialized variables to the original data. In this article, PHP serialization is introduced in detail. PHP can successfully store the properties and methods of the objects of the classes that you define before you play the objects of the class. Sometimes you may need an object to execute immediately after acting. For this purpose, PHP automatically looks for the _ _ sleep and _ _ wakeup methods.
Analysis on the use of PHP logical operator
About Windows PHP configuration Application Server steps
Experience: summary of PHP installation and setup skills
Demonstrate the use of the PHP substr function
Detailed introduction to the configuration of installing PHP5 under Windows
When an object is serialized by PHP, PHP calls the _ _ sleep method (if it exists). After performing an object, PHP calls the _ _ wakeup method. Neither of these methods accepts parameters. The _ _ sleep method must return an array of properties that need to be serialized. PHP discards the values of other properties. If there is no _ _ sleep method, PHP saves all properties. Example 1 shows how to serialize an object using the _ _ sleep and _ _ wakeup methods. The Id property is a temporary property that is not intended to remain in the object. The _ _ sleep method guarantees that the id property is not included in the serialized object. When the actor makes a User object, the _ _ wakeup method establishes the new value of the id property. This example is designed to be self-preserving. In actual development, you may find that objects that contain resources, such as images or data streams, need these methods.
Listing1 Object serialization class User {public $name; public $id; function _ _ construct () {/ / give user a unique ID assigns a different ID $this- > id = uniqid ();} function _ sleep () {/ / do not serialize this- > id does not serialize id return (array ("name");} function _ wakeup () {/ / give user a unique ID $this- > id = uniqid () }} / / create object create an object $u = new User; $u-> name = "Leon"; / / serialize it serialization note that the id attribute is not serialized, and the value of id is discarded $s = serialize ($u); / / unserialize it actor id is reassigned $u2 = unserialize ($s); / / u and $u2 have different IDs $u and $U2 have different ID print_r ($u); print_r ($U2) This is the end of the answer to the question about what is PHP serialization. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.