Object-oriented programming in PHP: Methods for developing large-scale PHP projects (4) Author: Luis Argerich Translator: limodou Advanced OOP technology in PHP After looking at the basic OOP concepts, I can show you more advanced technologies: Serialization (Serializing) PHP does not support persistent objects. In OOP, a persistent object is an object that can maintain state and functionality among references in multiple applications. This means having the ability to save the object to a file or database and be able to use it later. Load the object. This is the so-called serialization mechanism. PHP has a serialization method that can be called on an object, and the serialization method can return a string representation of the object. However, serialization only saves the member data of the object and not the methods. In PHP4, if you serialize the object into the string $s, then release the object, and then deserialize the object into $obj, you can continue to use the object's methods! I don't recommend doing this because (a) there is no guarantee in the documentation that this behavior will still work in future versions. (b) This may lead to a misunderstanding when you save a serialized version to disk and exit the script. When you later run this script, you cannot expect that when you deserialize an object, the object's methods will be there, because the string representation does not include methods at all. In short, serialization in PHP is very useful for saving member variables of objects. (You can also serialize related arrays and arrays into a file). example: ------------------------------------------------ -------------------------------- ------------------ -------------------------------------------------- --------------- You restored the member data, but not the methods (according to the documentation). This results in the only way to access member variables (you have no other way!) by something like using $obj2->x, so don't try it at home. There are some ways to solve this problem, I left them out because they are too bad for the purpose of this concise article. I will happily welcome fully serialized features in subsequent versions of PHP. Reprinted from PHPBuilder.com