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...