Fix idealcheckout_unserialize

Sorry, I don't feel like typing a message dedicated to this fix I made. Let's just post the code.

Original code:

function idealcheckout_unserialize($sString)
    {
        // Recalculate multibyte strings
        $sString = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $sString);
        return unserialize($sString);
    }

Error:

PHP Deprecated:  preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in ... on line ..

This means idealcheckout_unserialize is not php7 compatible.

My fix:

    // Unserialize data
    function idealcheckout_unserialize($sString)
    {
        // Recalculate multibyte strings
        $sString = preg_replace_callback('!s:(\d+):"(.*?)";!s',
            function($matches){
                return 's:'.strlen($matches[2]).':"'.$matches[2].'";';
            }, $sString);
        return unserialize($sString);
    }
© GeekLabInfo Fix idealcheckout_unserialize is a post from GeekLab.info. You are free to copy materials from GeekLab.info, but you are required to link back to http://www.geeklab.info

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...
Categories: IT

Leave a Reply