I’m currently working on zend framework and trying to store serialised version of an object let’s say
class customer{
protected $id;
public static function getInstanceById( $id )
{
$this->id=$id;
}
public function getOrders()
{
return array('pizza', 'pancake', 'etc');
}
}
and if I do
$customer = Customer::getInstanceById(1);
$content = serialize( $customer );
file_put_contents('file.txt', $content);
and later on I do
$data = file_get_contents('file.txt');
$customer = unserialize( $data );
$order = $customer->getOrders(); // <<<<<<<
this will throw error.
any idea how to restore the state of the object when unserializing it?
Please help!
Thanks
PHP docs is usually pretty thorough for these things. Check out the page on Object Serialization.