What happens when you serialize data? Seriously, I'm being bothered about what's the use of it, I have been searching through the web but they seem to give only the usage, not the reasons why to use it. .My task is to serialize data before inserting it as post_meta data in wordpress, and I'm a bit lost. Any help will be appreciated. Thanks.
Wiki: [S]erialization is the process of converting a data structure or object state into a format that can be stored [...] and "resurrected" later in the same or another computer environment.
Simply put, by serialization you can store an object in a transmittable and storable state. Converting an in-memory object to XML to send it to a SOAP service is serialization. PHP serializes your $_SESSION
array into a session file (at least by default). An ORM serializes your objects into an SQL query. JSON can represent serialized objects to be transferred between server and browser.
As for your question, I don't know how this applies to Wordpress though or what your question actually is, perhaps you should show some code.
WordPress has a reputation of being very portable but after reading a recent article on WPGarage.com, there is a certain condition in which the data in WordPress can become non-portable. It has to do with the serialization of data. However, they offer up a few different ways in which to deal with the problem so that you don’t lose data via a database dump.
Serialization
This process makes a storable representation of a value that is useful for storing or passing PHP values around without losing their type and structure.
UN-Serialization:
This process takes a single serialized variable and converts it back into a PHP value.
Data might need to be serialized to allow it to be successfully stored and retrieved from a database in a form that PHP can understand.
WordPress uses different functions for serialization. Check the following function references
<?php maybe_serialize( $data ); ?>
<?php is_serialized( $data ) ?>
Serialization makes it possible to save your object/data structure to memory or a file. When you de-serialize you are able to retrieve this information in the same state as it was before.
From Wikipedia:
http://en.wikipedia.org/wiki/Serialization
Serialization is the process of converting a data structure or object state into a format that can be stored (for example, in a file or memory buffer, or transmitted across a network connection link) and "resurrected" later in the same or another computer environment.
To answer your question, what actually happens is that the object is converted and structured in a way so it is possible to retrieve this data later. For example, you can serialize an object into an xml-structure.
Generally speaking, serialization is a way for store object or data structure in something you can store. Java has its own way, JavaScript has JSON and so on.
It's really useful for store objects or complex data structure in databases.
You ask why do we serialize data . Data is serialised for the purpose of storing or transmitting in a format ( as a series of bits ) , the stored format of the bits make sense when it is recreated at the recieving end , this recreation can happen in another envirornment or in another application than the application which did the serialisation .