This is simple example to understand serialize and unserialize a object in php.
we covert object into string using serialization and use this object current status (with assign values) after unserialization on other page..
c.php
<?php class A {
public $one ;
public function A($val) {
$this->one=$val;
// echo $this->one;
}
function display(){
echo $this->one;
}
}
?>
c.php a file have class with name A.
a.php
<?
require_once "c.php";
$ob= new A( by Pankaj Raghuwanshi : Object Searlization. );
$ob->display(); // Output is: by Pankaj Raghuwanshi : Object Searlization.
$s = serialize($ob);
// echo $s will show a string of an object
?>
<br><A href= b.php?s=<?=$s;?> >B-file</a>
我们用手法将这个物体编成雕像,然后通过该插图进入另一页。
Note :,我们可以将这一页数通过另一页,采用各种方法,如使用会议,我们可以节省到行文,并用另一页,但文本除外。
我们将在另一个档案名称(b.php)上将这个物体永久化。
b.php
<?
require_once "c.php";
$ob = unserialize($_GET[s]);
$ob->display();
// Output is: by Pankaj Raghuwanshi : Object Searlization.
?>
after unserialization, object showing same behavior like a.php file
and assign value of a.php still is in memory of object . if we will unserialize this object after many http request . Object will persist all assign values in their memory.