In previous versions, serializing an object will lose the functions attached, but in php5 it’s no longer a problem.
Some test code here:
$obj = new Model_Film_Movie();
$obj->setID(12);
$obj->setMovie('a test movie');
$objflattened = serialize($obj);
echo '<pre>';
$objnew = unserialize($objflattened);
//var_dump($objflattened, $objnew);
echo $objnew->getMovie();
exit;
I am sure this will make the ORM pattern much more useful in php apps and websites
About this blog
I had a website about 10 year ago? Couldn’t really remember now, but it was surely a long, long time ago, and I stopped updating it cos I was occupied by all the work and hobbies - ironically, these were all web-related.
Finally, I decided to revive my webiste, and this time, in the form of a blog - hope this time I can keep it updated. Well, I’ve downloaded the iphone wordpress app, hoping it will help.
admin
May 13th, 2009 at 3:33 pm
apparently, this works with caching as well.
// following the codes above.
$fname = 'D:\Download\obj.txt';
$h = fopen($fname, 'w+');
fwrite($h, $objflattened);
fclose($h);
//var_dump($objflattened, $objnew);
$objnew = unserialize(file_get_contents($fname));
echo $objnew->getMovie();
admin
May 13th, 2009 at 3:58 pm
even better:
multiple object caching is also doable:
$obj = new Model_Film_Movie();
$obj->setID(12);
$obj->setMovie('a test movie');
$r = new SBS_Model_Film_Review();
$r->setReview('hello world');
$r->setOneLiner('yo yo yo');
$obj->setMasterReview($r);
$objflattened = serialize($obj);
echo '