Skip to content

Commit

Permalink
Added Serializable interface and methods to JTable. Fixes #16185.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Champion committed May 23, 2017
1 parent 61b9fcc commit 1d7d05c
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion libraries/joomla/table/table.php
Expand Up @@ -19,7 +19,7 @@
* @since 11.1
* @tutorial Joomla.Platform/jtable.cls
*/
abstract class JTable extends JObject implements JObservableInterface, JTableInterface
abstract class JTable extends JObject implements JObservableInterface, JTableInterface, Serializable
{
/**
* Include paths for searching for JTable classes.
Expand Down Expand Up @@ -1711,4 +1711,30 @@ protected function _unlock()

return true;
}

/**
* Implement Serializable. Prevent DB object getting into serialized string.
*
* @return string
*/
public function serialize()
{
$vars = get_object_vars($this);
unset ($vars['_db']);
return serialize($vars);
}

/**
* Implement Serializable. DB object needs to be restored separately as it was excluded from serialization.
*
* @param string $data
*/
public function unserialize($data)
{
$vars = unserialize($data);
foreach ($vars as $key=>$value) {
$this->$key = $value;
}
$this->_db = JFactory::getDBO();
}
}

0 comments on commit 1d7d05c

Please sign in to comment.