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
Serialization problem
Moderator: General Moderators
Re: Serialization problem
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
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
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