note 127781 added to function.unserialize
| From: | OscarZarrus at main dot php dot net | Date: | Thu, 20 Oct 2022 09:28:10 +0000 |
| Subject: | note 127781 added to function.unserialize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219731@lists.php.net to get a copy of this message | ||
For those who are looking for an efficient solution for handling controversial "FALSE",
they can use this function which in case of non-unserializable string, instead of a
"FALSE", throws an Exception. Vice versa it returns the unserialized variable.
<?php
/**
* @param string $serializedString
* @return mixed
* @throws Exception
*/
function UnSerialize(string $serializedString) {
$_unserialized = @unserialize($serializedString);
if ($serializedString === serialize(false) || $_unserialized !== false){
return $_unserialized;
}
throw new Exception("Non-unserializable string");
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.159.161 (proxied: 151.19.23.136)
----
Manual Page -- https://php.net/manual/en/function.unserialize.php
Edit -- https://main.php.net/note/edit/127781
Del: integrated -- https://main.php.net/note/delete/127781/integrated
Del: useless -- https://main.php.net/note/delete/127781/useless
Del: bad code -- https://main.php.net/note/delete/127781/bad+code
Del: spam -- https://main.php.net/note/delete/127781/spam
Del: non-english -- https://main.php.net/note/delete/127781/non-english
Del: in docs -- https://main.php.net/note/delete/127781/in+docs
Del: other reasons-- https://main.php.net/note/delete/127781
Reject -- https://main.php.net/note/reject/127781
Search -- https://main.php.net/manage/user-notes.php