I'am using memcache to store PHP class object using serialize and unserialize. Is any way to get back original class object using new Method?
My example:
class Test
{
public $id;
public function __construct($id)
{
if (InCache($id)) {
return unserialize(GetFromCache($id));
} else {
$this->id = $id;
SaveToCache(serialize($this));
}
}
}
Calling:
$t = new Test(1);
If ID is in cache or NOT, I need back same output:
Test Object
(
[id] => 1
)
Anybody can help?