Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save manojind/9f18bbecaeb3e2bbfb056a634ade62a2 to your computer and use it in GitHub Desktop.
Save manojind/9f18bbecaeb3e2bbfb056a634ade62a2 to your computer and use it in GitHub Desktop.
ROOT directory
1. public_html/vendor/magento/framework/Serialize/Serializer/Json.php
2. Just replace below fucntion (unserialize) and add new function OR just download attached file and replace with default
public function unserialize($string)
{
if($this->is_serialized($string))
{
$string = $this->serialize($string);
}
$result = json_decode($string, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \InvalidArgumentException('Unable to unserialize value.');
}
return $result;
}
3. Add new function :
function is_serialized($value, &$result = null)
{
if (!is_string($value))
{
return false;
}
if ($value === 'b:0;')
{
$result = false;
return true;
}
$length = strlen($value);
$end = '';
switch ($value[0])
{
case 's':
if ($value[$length - 2] !== '"')
{
return false;
}
case 'b':
case 'i':
case 'd':
$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;
}
@xitfreelance
Copy link

Thanks
I just updated magneto 2.2.5 but there was lot off error Unserialize Value solved lot of but there still lot off issues like Module chema_version and data_version .

Created 20 minutes ago •

@ritaxit
Copy link

ritaxit commented Sep 4, 2018

Thanks for help

@manojind
Copy link
Author

manojind commented Sep 5, 2018

Welcome

Let me know if you need any other help ?

@jkiranmai
Copy link

Thanks
while upgrading to Magento 2.3 the same issue occured "Unable to unserialize value, string is corrupted."
The above code does not solve my problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment