Skip to content

Instantly share code, notes, and snippets.

@cbwar
Created April 27, 2018 13:37
Show Gist options
  • Save cbwar/cc3a66098a0881334832355611f1371a to your computer and use it in GitHub Desktop.
Save cbwar/cc3a66098a0881334832355611f1371a to your computer and use it in GitHub Desktop.
Unserialize to specified class
<?php
function unserializeToClass($object, $class = 'stdClass')
{
return unserialize(preg_replace('/^O:\d+:"[^"]++"/', 'O:' . strlen($class) . ':"' . $class . '"', $object));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment