PHP object-oriented programming: methods for developing large PHP projects (4)

Source: Internet
Author: User
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 more advanced technology: serialization PHP does not support permanent objects, and in OOP, SyntaxHighl

PHP object-oriented programming: method for developing large PHP projects (4) Author: Luis Argerich translator: limodou advanced OOP technology of PHP after reading the basic OOP concepts, I can show you more advanced technology: 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.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.