2

I am rather new to OpenCart 2.1 and as part of an attempt to install new theme i have encountered what seems to be an issue migrating to PHP 5.5. The error that i am getting is:

Unknown: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /Applications/MAMP/htdocs/projects/phpproject1/upload/admin/controller/module/tg_themegloballite_settings.php on line 442. Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/projects/phpproject1/upload/admin/index.php:80) in /Applications/MAMP/htdocs/projects/phpproject1/upload/system/library/response.php on line 12

I believe the error is within file tg_themegloballite_settings.php on line 442 (somewhere within below block):

          function mb_unserialize($serial_str) {
              $out = preg_replace('!s:(\d+):"(.*?)";!se', 
          "'s:'.strlen('$2').':\"$2\";'", $serial_str );
              return unserialize($out);
          }

I've been trying to fix it for a while now but cannot seem to get it to work, so any assistance will be highly appreciated.

HDP
  • 4,005
  • 2
  • 36
  • 58
Sky21.86
  • 627
  • 2
  • 9
  • 26

1 Answers1

0

This is a warning because the e modifier deprecation on preg_replace function (see http://php.net/manual/en/migration55.deprecated.php)

The equivalent replacement using preg_replace_callback is:

<?php

function mb_unserialize($serial_str) {
    $out = preg_replace_callback(
        '!s:(\d+):"(.*?)";!s',
        function ($matches) {
            return 's:' . strlen($matches[2]) . ':\"' . $matches[2] . '\";';
        },
        $serial_str);
    return unserialize($out);
}

echo "Function test: " . mb_unserialize('s:7:"my test"') . "\n";

References: http://php.net/manual/en/function.preg-replace-callback.php

Eduardo
  • 657
  • 1
  • 9
  • 28