note 96938 added to function.unserialize

From: Date: Wed, 24 Mar 2010 04:46:26 +0000
Subject: note 96938 added to function.unserialize
Groups: php.notes 
Request: Send a blank email to php-notes+get-167340@lists.php.net to get a copy of this message
Here's a simple function to get the class of a serialized string (that is, the type of object that will be returned if it's unserialized): <?php function get_serial_class($serial) { $types = array('s' => 'string', 'a' => 'array', 'b' => 'bool', 'i' => 'int', 'd' => 'float', 'N;' => 'NULL'); $parts = explode(':', $serial, 4); return isset($types[$parts[0]]) ? $types[$parts[0]] : trim($parts[2], '"'); } ?> I use this when saving a serialized object to a cookie, to make sure it is the right type when I go to unserialize it. The type names are the same format/case as you would see if you did a var_dump(). ---- Server IP: 216.235.13.26 Probable Submitter: 24.78.148.130 ---- Manual Page -- http://www.php.net/manual/en/function.unserialize.php Edit -- https://master.php.net/note/edit/96938 Del: integrated -- https://master.php.net/note/delete/96938/integrated Del: useless -- https://master.php.net/note/delete/96938/useless Del: bad code -- https://master.php.net/note/delete/96938/bad+code Del: spam -- https://master.php.net/note/delete/96938/spam Del: non-english -- https://master.php.net/note/delete/96938/non-english Del: in docs -- https://master.php.net/note/delete/96938/in+docs Del: other reasons-- https://master.php.net/note/delete/96938 Reject -- https://master.php.net/note/reject/96938 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167340) next »