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
//
// session save handling of SimpleXMLElement objects
// (applies to/ tested with PHP 5.1.5 and PHP 5.2.1)
// The myClass pattern allows for conveniently accessing
// XML structures while being session save
//
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();
} // __construct()
public function __destruct()
{
$this->s_XMLconfig =
$this->o_XMLconfig->asXML();
unset($this->o_XMLconfig); // this object would
otherwise crash
// the subsequent call of
// session_start()!
} // __destruct()
public function __wakeup()
{
$this->o_XMLconfig =
simplexml_load_string($this->s_XMLconfig);
} // __wakeup()
} // class myClass
?>
----
Server IP: 217.160.72.57
Probable Submitter: 217.24.12.178
----
Manual Page -- http:/
/www.php.net/manual/en/ref.simplexml.php
Edit -- https://master
.php.net/note/edit/74192
Del: integrated -- h
ttps://master.php.net/note/delete/74192/integrated
Del: useless -- http
s://master.php.net/note/delete/74192/useless
Del: bad code -- htt
ps://master.php.net/note/delete/74192/bad+code
Del: spam -- https:/
/master.php.net/note/delete/74192/spam
Del: non-english --
https://master.php.net/note/delete/74192/non-english
Del: in docs -- http
s://master.php.net/note/delete/74192/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/74192
Reject -- https://mast
er.php.net/note/reject/74192
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|