Making SimpleXMLElement objects session save.
Besides the effect of not surviving sessions, the SimpleXMLElement object may even crash the session_start() function when trying to re-enter the session!
To come up with a solution for this, I used a pattern as follows. The core idea is to transform the SimpleXMLElement between session calls to and from a string representation which of course is session save.
<?php
class myClass
{
private $o_XMLconfig = null;
private $s_XMLconfig = '';
public function __construct($args_configfile)
{
$this->o_XMLconfig = simplexml_load_file($args_configfile);
$this->s_XMLconfig = $this->o_XMLconfig->asXML();
} public function __destruct()
{
$this->s_XMLconfig = $this->o_XMLconfig->asXML();
unset($this->o_XMLconfig); } public function __wakeup()
{
$this->o_XMLconfig = simplexml_load_string($this->s_XMLconfig);
} } ?>