Serialization Example in Object Oriented PHP

<?php

/*Serialization of data means converting the data into a string of byte in such a way that you can produce original data again from the string ..

one can serialize any type of data (except type resource) …

This is actually like encoding and decoding the data … serialize() function encode the data and unserialize() function unserialize the data … this serilization may helpfull for session mechanism …*/

class freak
{
private $robot_name;

function __construct($name)
{
$this->robot_name = $name;
}
function display()
{
echo $this->robot_name;
}
}

$ins = new freak(‘x2ff4’);
$ser = serialize($ins);
$ins2 = unserialize($ser);
$ins2-> display();

?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s