You are currently viewing Migrating Magento Websites to PHP7

Migrating Magento Websites to PHP7

  • Post published:April 15, 2016

Magento is one of the biggest and most popular e-commerce platforms written in PHP. However, migrating Magento sites to PHP 7 can prove to be a tedious task. While most of the Magento code is still valid in PHP 7, a few situations can arise where there are incompatibilities. This article will take you through these incompatibilities step by step to ensure a hassle free Magento to PHP 7 migration.

Following are the three main issues and their solutions:

1- Uniform Variable Syntax Errors

The following files cause variable syntax errors that need to be resolved with the help of steps mentioned below:

a) app/code/core/Mage/Core/Model/Layout.php:555

A fatal error is caused by this file which crashes Magento. To override this file, go to line#555 and replace $out .= $this->getBlock($callback[0])->$callback[1](); with $out .= $this->getBlock($callback[0])->{$callback[1]}();.

b) app\code\core\Mage\ImportExport\Model\Import:135

Magento CSV importer is affected by this file and you need to nullify it first. After that override _validateFile() function and go to line#135 and replace $params[‘object’]->$params[‘method’]($filePath); with $params[‘object’]->{$params[‘method’]}($filePath);.

c) app\code\core\Mage\ImportExport\Model\Export\Entity\Product\Type\Abstract.php:99

The abstract class issue has an impact on Magento‘s export functionality. Magento extends the following three classes from this abstract class:

  • Mage_ImportExport_Model_Export_Entity_Product_Type_Configurable
  • Mage_ImportExport_Model_Export_Entity_Product_Type_Grouped
  • Mage_ImportExport_Model_Export_Entity_Product_Type_Simple

The root cause of this error inside the above mentioned classes is actually in line#99, so you need to override these three classes in your local code pool. To override the Attribute() function, go to line#99 and replace $data[‘filter_options’] = $this->$data[‘options_method’](); with $data[‘filter_options’] = $this->{$data[‘options_method’]}();.

d) app\code\core\Mage\ImportExport\Model\Export\Entity\Customer.php:250

This file affects export customers’ functionality. To override the above mentioned file, go to line#250 and replace $data[‘filter_options’] = $this->$data[‘options_method’](); with $data[‘filter_options’] = $this->{$data[‘options_method’]}();.

e) lib\Varien\File\Uploader.php:259

An issue may emerge here that file uploading won’t work. As Magento extends Mage_Core_Model_File_Uploader from the above class, so you need to override it and rewrite _validateFile() function. Now, go to line#259 and replace $params[‘object’]->$params[‘method’]($this->_file[‘tmp_name’]); with $params[‘object’]->{$params[‘method’]}($this->_file[‘tmp_name’]);.

2- Type Casting Issue


User login won’t work in light of the fact that Magento Sessions don’t deal with PHP 7. read($sessId) function should return a string, so typecast the return variable by replacing return $data; with return (string)$data;.

3- Incorrect Grand Total

This issue can arise due to wrong sort order of subtotal, discount, and shipping etc. You need to correct the sort order by creating an extension. For this, put the following code in config.xml of the created extension: