note 112823 added to function.unserialize
| From: | Ray.PaseuroftenusesGmail | Date: | Fri, 26 Jul 2013 13:41:17 +0000 |
| Subject: | note 112823 added to function.unserialize | ||
| Groups: | php.notes php.notes | ||
| Request: | Send a blank email to php-notes+get-195782@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.
Prior to PHP 5.3, this was not an issue. But after PHP 5.3 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. 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.unserialize.php
Edit -- https://master.php.net/note/edit/112823
Del: integrated -- https://master.php.net/note/delete/112823/integrated
Del: useless -- https://master.php.net/note/delete/112823/useless
Del: bad code -- https://master.php.net/note/delete/112823/bad+code
Del: spam -- https://master.php.net/note/delete/112823/spam
Del: non-english -- https://master.php.net/note/delete/112823/non-english
Del: in docs -- https://master.php.net/note/delete/112823/in+docs
Del: other reasons-- https://master.php.net/note/delete/112823
Reject -- https://master.php.net/note/reject/112823
Search -- https://master.php.net/manage/user-notes.php