Page 1 of 1
Serialization problem
Posted: Thu Nov 03, 2011 10:35 am
by cariparo
Hi All,
I need to save to my DB the content of a SplDoublyLinkedList variable to load it later.
It seems that php serialize() doesn't work for this kind of class, does anyone know an alternative to do that ?
Thanks in advance,
Carip
Re: Serialization problem
Posted: Thu Nov 03, 2011 2:31 pm
by Weirdan
I wondering what is the reason you have to use linked list instead of plain old php array in the first place? Anyways, as it doesn't implement Serializable, you'd have to get data from it and put it into a serializable container in a way you can restore your linked list from :
Code: Select all
// serialize:
$container = array();
foreach ($list as $elt) $container[] = $elt;
$data = serialize($container);
//unserialize:
$list = new SplDoublyLinkedList;
foreach (unserialize($data) as $elt) $list->push($elt);
Re: Serialization problem
Posted: Fri Nov 04, 2011 2:19 am
by cariparo
Thanks
unfortunately this is not my code, i'm revamping an existing one..
As I understand the only way is to get data from it..
Thanks
Carip