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.