PHP object-oriented programming development of large PHP projects method 4 _ PHP Tutorial

Source: Internet
Author: User
Method 4 of PHP object-oriented programming for large-scale PHP project development. PHP's advanced OOP technology after reading the basic OOP concepts, I can show you more advanced technology: serialization PHP does not support permanent objects, in OOP, permanent objects can be advanced OOP technology in PHP.
After reading the basic OOP concepts, I can show you more advanced technologies:
Serializing)
PHP does not support permanent objects. in OOP, permanent objects are objects that can maintain the state and function in the references of multiple applications, this means that an object can be saved to a file or database and can be loaded 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:
--------------------------------------------------------------------------------
$ Obj = new Classfoo ();
$ Str = serialize ($ obj );
// Save $ str to disk
// A few months later
// Input str from the disk
$ Obj2 = unserialize ($ str)
?> --------------------------------------------------------------------------------
You have recovered the member data, but do not include methods (as described in this 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.
Previous Page

After reading the basic OOP concepts, idea can show you more advanced technologies: serialization PHP does not support permanent objects, in OOP, permanent objects can be stored in...

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.