Method 4 of developing large-scale PHP projects using object-oriented programming in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 17:29:02
Original
776 people have browsed it

Advanced OOP technology in PHP
After looking at the basic OOP concepts, I can show you more advanced technologies:
Serializing (Serializing)
PHP does not support persistent objects. Permanent objects in OOP An object that can maintain state and functionality across references from multiple applications, which means having the ability to save the object to a file or database and load the object later. 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, PHP serialization is very useful for saving member variables of objects. (You can also serialize related arrays and arrays into a file).
Example:
--------------------------------------------- ---------------------------------------------
$obj= new Classfoo();
$str=serialize($obj);
//Save $str to disk
//A few months later
//Load str from disk
$obj2=unserialize($str)
?>------------------------------------------------ -----------------------------------------------
You have recovered Member data, but not 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'm leaving them out because they are too bad for this concise article.
I will happily welcome fully serialized features in subsequent versions of PHP.
Previous page Next page

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531730.htmlTechArticleAdvanced OOP Technology in PHP After seeing the basic OOP concepts, I can show you more advanced technology : Serializing (Serializing) PHP does not support permanent objects. In OOP, permanent objects can be...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template