Skip to content

Instantly share code, notes, and snippets.

@WebBamboo
Created January 20, 2018 16:17
Show Gist options
  • Save WebBamboo/556e095877403ca1202e0494502dc0dc to your computer and use it in GitHub Desktop.
Save WebBamboo/556e095877403ca1202e0494502dc0dc to your computer and use it in GitHub Desktop.
<?php
function isSerialized($data)
{
set_error_handler(function($errno, $errstr){
if($errno == E_WARNING) {
throw new \Exception($errstr);
} else if($errno == E_NOTICE) {
throw new \Exception($errstr);
}
}, E_ALL);
try
{
$unserialized = unserialize($data);
return true;
}
catch(\Throwable $ex)
{
return false;
}
restore_error_handler();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment