note 120110 added to ref.session

From: Date: Wed, 02 Nov 2016 14:19:25 +0000
Subject: note 120110 added to ref.session
Groups: php.notes 
Request: Send a blank email to php-notes+get-207005@lists.php.net to get a copy of this message
PHP 5+ you cannot store StdClass and similar built-in objects in the session. The class definitions do not exist in a way that allows PHP to serialize/unserialize the information. This results in a fatal error; the entire contents of the session is lost. <?php error_reporting(E_ALL); session_start(); var_dump($_SESSION); // INITIAL STATE $_SESSION['hello'] = 'World'; var_dump($_SESSION); // MUTATED STATE // AN XML STRING FOR TEST DATA $xml = <<<EOD <?xml version="1.0"?> <families> <parent> <child index="1" value="Category 1">Child One</child> </parent> </families> EOD; // STORE THE SimpleXMLElement OBJECT IN THE SESSION $_SESSION['obj'] = SimpleXML_Load_String($xml); ---- Server IP: 72.52.91.14 Probable Submitter: 98.169.66.145 ---- Manual Page -- http://php.net/manual/en/ref.session.php Edit -- https://master.php.net/note/edit/120110 Del: integrated -- https://master.php.net/note/delete/120110/integrated Del: useless -- https://master.php.net/note/delete/120110/useless Del: bad code -- https://master.php.net/note/delete/120110/bad+code Del: spam -- https://master.php.net/note/delete/120110/spam Del: non-english -- https://master.php.net/note/delete/120110/non-english Del: in docs -- https://master.php.net/note/delete/120110/in+docs Del: other reasons-- https://master.php.net/note/delete/120110 Reject -- https://master.php.net/note/reject/120110 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#207005) next »