The documents of classes and objects have the following: In order to be able to unserialize () an object, the class of this object must be defined.
Prior to PHP 5.3, this was not a problem. But after PHP 5.3, the object created by SimpleXML_Load_String () cannot be serialized. Attempting to do this will result in a run-time failure, throwing an exception. If you store such an object in $ _SESSION, you will receive an error message after this:
Fatal error: throw exception "Exception" with the message "Serialization" SimpleXMLElement "not allowed" in [no active file]: 0 Trace of the stack: # 0 {main} selected [no active file] in line 0
All session content will be lost. Hope this helps someone!
<?php // RAY_temp_ser.php error_reporting(E_ALL); session_start(); var_dump($_SESSION); $_SESSION['hello'] = 'World'; var_dump($_SESSION); // AN XML STRING FOR TEST DATA $xml = '<?xml version="1.0"?> <families> <parent> <child index="1" value="Category 1">Child One</child> </parent> </families>'; // MAKE AN OBJECT (GIVES SimpleXMLElement) $obj = SimpleXML_Load_String($xml); // STORE THE OBJECT IN THE SESSION $_SESSION['obj'] = $obj;
Posted by: Ray.Paseur
what am I doing since "Stefan Gerig" said passed the XML data to a string
$_SESSION['obj'] = (string)$obj;
abdulwadood
source share