From 1d7d05c3999e6ddc5e8f222b91042bd1c7704719 Mon Sep 17 00:00:00 2001 From: Simon Champion Date: Tue, 23 May 2017 16:40:48 +0100 Subject: [PATCH] Added Serializable interface and methods to JTable. Fixes #16185. --- libraries/joomla/table/table.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/libraries/joomla/table/table.php b/libraries/joomla/table/table.php index ee485fcf9039c..cdf2b43ceac3e 100644 --- a/libraries/joomla/table/table.php +++ b/libraries/joomla/table/table.php @@ -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. @@ -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(); + } }