pronto.ee

Tomorrow will be cancelled due to lack of interest

Upgrading to Magento 1.9.4.0, PHP 7.2 compatibility problem

Magento
Magento

Magento 1.9.4.0 should support PHP 7.2 and fortunately it mostly does. However there’s an upgrade script from older Magento versions which, lets say, has room for improvements.

When your original Magento is old enough (I tested it on Magento 1.7.0.2) the process will throw following error message:

Fatal error: Uncaught Error: [] operator not supported for strings in /magento-path/app/code/core/Mage/Usa/sql/usa_setup/upgrade-1.6.0.1-1.6.0.2.php on line 93
( ! ) Error: [] operator not supported for strings in /magento-path/app/code/core/Mage/Usa/sql/usa_setup/upgrade-1.6.0.1-1.6.0.2.php on line 93

The culprit of the message above is here:

    $newValue = '';
    if (stripos($oldValue['path'], 'free_method') && isset($oldToNewMethodCodesMap[$oldValue['value']])) {
        $newValue = $oldToNewMethodCodesMap[$oldValue['value']];
    } else if (stripos($oldValue['path'], 'allowed_methods')) {
        foreach (explode(',', $oldValue['value']) as $shippingMethod) {
            if (isset($oldToNewMethodCodesMap[$shippingMethod])) {
                $newValue[] = $oldToNewMethodCodesMap[$shippingMethod];
            }
        }
        $newValue = implode($newValue, ',');
    } else {
        continue;
    }

As you can see $newValue is declared as a string and almost immediately expected to be an array (provided that conditions are right). No good. Simplest way to resolve it is to redeclare it as an array when it happens:

    $newValue = '';
    if (stripos($oldValue['path'], 'free_method') && isset($oldToNewMethodCodesMap[$oldValue['value']])) {
        $newValue = $oldToNewMethodCodesMap[$oldValue['value']];
    } else if (stripos($oldValue['path'], 'allowed_methods')) {
        $newValue = [];
        foreach (explode(',', $oldValue['value']) as $shippingMethod) {
            if (isset($oldToNewMethodCodesMap[$shippingMethod])) {
                $newValue[] = $oldToNewMethodCodesMap[$shippingMethod];
            }
        }
        $newValue = implode($newValue, ',');
    } else {
        continue;
    }

Post a comment