PHP object-oriented programming: method for developing large PHP projects (IV) _ PHP Tutorial-php Tutorial
Source: Internet
Author: User
PHP object-oriented programming: method for developing large PHP projects (4) (reproduced ). PHP object-oriented programming: method for developing large PHP projects (4) Author: LuisArgerich translator: limodouPHP advanced OOP technology after reading the basic OOP concepts, I can show you PHP object-oriented programming: how to develop large PHP projects (4) Author: Luis Argerich translator: after reading the basic OOP concepts, limodou PHP's advanced OOP technology will show you more advanced technologies: serialization PHP does not support permanent objects, in OOP, permanent objects are objects that can maintain state and function in the reference of multiple applications, which means they can be saved to a file or database, you can also load objects later. This is the so-called serialization mechanism. PHP has a serialization method, which can be called through an object. the serialization method can return the string representation of an object. However, serialization only saves the member data of the object without the package method. In PHP4, if you serialize an object to the string $ s, release the object, and deserialize the object to $ obj, you can continue to use the object method! I do not recommend that you do this because (a) the document does not guarantee that this behavior can still be used in future versions. (B) this may lead to a misunderstanding when you save a serialized version to the disk and exit the script. When you run this script in the future, you cannot expect that when deserializing an object, the object method will also be there, because the string representation does not include the method at all. All in all, PHP Serialization is very useful for saving object member variables. (You can also serialize related arrays and arrays to a file ). Example :-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- You restored the member data, but did not include methods (as described in the document ). As a result, you can only use $ obj2-> x to access member variables (you have no other way !) So do not try it at home. There are some ways to solve this problem. I keep it because they are too bad for this concise article. I would be very pleased to welcome the full serialization feature in subsequent PHP versions.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.