Login   Register  
PHP Classes
elePHPant
Icontem

File: serialize-example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of nghia nguyen  >  Recursive reference serialize  >  serialize-example.php  >  Download  
File: serialize-example.php
Role: Example script
Content type: text/plain
Description: serialize example
Class: Recursive reference serialize
Serialize objects with cyclic references
Author: By
Last change: faster by ReferencedObjectSerializeMarker class
Date: 5 years ago
Size: 706 bytes
 

Contents

Class file image Download
<?php
// $object1&$object2 are circle referencing
include_once "TSClass1.php";
include_once 
"SerializeManager.php";
$object1 = new TSClass1();
$object2 = new TSClass2();
$object1->var1 "var1";
$object1->selfRef $object1;
$object1->ref1 $object2;
$object2->var2 "var2";
$object2->setRef2($object1);
$str SerializeManager::instance()->serializeObject($object1);
echo 
$str;
$newo SerializeManager::instance()->unserializeObject($str);

//we get $str = C:8:"TSClass1":167:{1:a:2:{s:4:"var1";s:4:"var1";s:4:"ref1";C:8:"TSClass2":105:{2:a:2:{s:5:"_ref2";O:31:"ReferencedObjectSerializeMarker":1:{s:9:"objectKey";i:1;}s:4:"var2";s:4:"var2";}}}}
//and $newo is clone of $object1
?>