- unserialize: documentation ( source)
- serialize: documentation ( source)
<?php
class Rowset implements Serializable
{
/**
* @var array
*/
private $_results;
public function __construct(array $results)
{
$this->_results = $results;
}
public function serialize()
{
return serialize($this->_results);
}
public function unserialize($serialized_data)
{
$this->_results = unserialize($serialized_data);
}
}
class Item implements Serializable
{
const ITEM_TYPE_IMAGE = 'image';
const ITEM_TYPE_VIDEO = 'video';
/**
* @var string
*/
protected $_service_name;
/**
* @var string
*/
protected $_item_id;
/**
* @var string
*/
protected $_item_url;
/**
* @var string
*/
protected $_user_id;
/**
* @var string
*/
protected $_text;
/**
* @var string
*/
protected $_post_url;
/**
* @var string
*/
protected $_item_type;
/**
* @var string
*/
protected $_datetime;
/**
* @param string $user_id
* @return $this
*/
public function setUserId($user_id)
{
$this->_user_id = $user_id;
return $this;
}
/**
* @return string
*/
public function getUserId()
{
return $this->_user_id;
}
/**
* @param string $datetime
* @return $this
*/
public function setDatetime($datetime)
{
$this->_datetime = $datetime;
return $this;
}
/**
* @return string
*/
public function getDatetime()
{
return $this->_datetime;
}
/**
* @param string $item_id
* @return $this
*/
public function setItemId($item_id)
{
$this->_item_id = $item_id;
return $this;
}
/**
* @return string
*/
public function getItemId()
{
return $this->_item_id;
}
/**
* @param string $item_type
* @return $this
*/
public function setItemType($item_type)
{
$this->_item_type = $item_type;
return $this;
}
/**
* @return string
*/
public function getItemType()
{
return $this->_item_type;
}
/**
* @param string $item_url
* @return $this
*/
public function setItemUrl($item_url)
{
$this->_item_url = $item_url;
return $this;
}
/**
* @return string
*/
public function getItemUrl()
{
return $this->_item_url;
}
/**
* @param string $post_url
* @return $this
*/
public function setPostUrl($post_url)
{
$this->_post_url = $post_url;
return $this;
}
/**
* @return string
*/
public function getPostUrl()
{
return $this->_post_url;
}
/**
* @return string
*/
public function getServiceName()
{
return $this->_service_name;
}
/**
* @param string $text
* @return $this
*/
public function setText($text)
{
$this->_text = $text;
}
/**
* @return string
*/
public function getText()
{
return $this->_text;
}
public function serialize()
{
return serialize($this->_datetime);
}
public function unserialize($serialized_data)
{
}
}
$item = new Item();
$item->setText('yoyo');
$rowset = new Rowset(array($item));
echo serialize($rowset);