Voting

: zero plus eight?
(Example: nine)

The Note You're Voting On

OscarZarrus
2 years ago
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
* @param array $options
* @return mixed
* @throws Exception
*/
function UnSerialize(string $serializedString, array $options = []) {
$_unserialized = @unserialize($serializedString, $options);
if (
$serializedString === serialize(false) || $_unserialized !== false){
return
$_unserialized;
}
throw new
Exception("Non-unserializable string");

}

?>

<< Back to user notes page

To Top