public static function is_serialized($value, &$result = NULL)
{
// Bit of a give away this one
if (!is_string($value)) {
return FALSE;
}
// Serialized FALSE, return TRUE. unserialize() returns FALSE on an
// invalid string or it could return FALSE if the string is serialized
// FALSE, eliminate that possibility.
if ('b:0;' === $value) {
$result = FALSE;
return TRUE;
}
$length = strlen($value);
$end = '';
if (isset($value[0])) {
switch ($value[0]) {
case 's':
if ('"' !== $value[$length - 2]) {
return FALSE;
}
case 'b':
case 'i':
case 'd':
// This looks odd but it is quicker than isset()ing
$end .= ';';
case 'a':
case 'O':
$end .= '}';
if (':' !== $value[1]) {
return FALSE;
}
switch ($value[2]) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
break;
default:
return FALSE;
}
case 'N':
$end .= ';';
if ($value[$length - 1] !== $end[0]) {
return FALSE;
}
break;
default:
return FALSE;
}
}
if (($result = @unserialize($value)) === FALSE) {
$result = NULL;
return FALSE;
}
return TRUE;
}