note 113041 deleted from function.session-start by peehaa

From: Date: Mon, 27 Feb 2017 08:19:11 +0000
Subject: note 113041 deleted from function.session-start by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208862@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- In the Classes and Objects docs, there is this: In order to be able to unserialize() an object, the class of that object needs to be defined. An object made by SimpleXML_Load_String() cannot be serialized. An attempt to do so will result in a run-time failure, throwing an exception. If you store such an object in $_SESSION, you will get a post-execution error that says this: Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'SimpleXMLElement' is not allowed' in [no active file]:0 Stack trace: #0 {main} thrown in [no active file] on line 0 The entire contents of the session will be lost. This script demonstrates the failure. Hope this saves someone some time! <?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;

« previous php.notes (#208862) next »