note 113041 added to function.session-start
| From: | Anonymous | Date: | Wed, 21 Aug 2013 17:56:14 +0000 |
| Subject: | note 113041 added to function.session-start | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-196042@lists.php.net to get a copy of this message | ||
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;
----
Server IP: 192.41.42.26
Probable Submitter: 98.169.50.31
----
Manual Page -- http://php.net/manual/en/function.session-start.php
Edit -- https://master.php.net/note/edit/113041
Del: integrated -- https://master.php.net/note/delete/113041/integrated
Del: useless -- https://master.php.net/note/delete/113041/useless
Del: bad code -- https://master.php.net/note/delete/113041/bad+code
Del: spam -- https://master.php.net/note/delete/113041/spam
Del: non-english -- https://master.php.net/note/delete/113041/non-english
Del: in docs -- https://master.php.net/note/delete/113041/in+docs
Del: other reasons-- https://master.php.net/note/delete/113041
Reject -- https://master.php.net/note/reject/113041
Search -- https://master.php.net/manage/user-notes.php