How to fix Magento 1.9 errors on PHP 7
Magento is one of the largest and most used e-commerce platforms. It is developed in PHP. In early days initial Magento release was known as ‘Bento’, in March 31, 2008. That time PHP version was 5.2. Actually Magento 1.9 that supports PHP versions up to 5.5.x , but the platform also works great on PHP v5.6.
Nowadays PHP 7 and PHP 7.1 are being used on servers and Magento 2 (new version of Magento) love latest PHP versions, but unfortunately when you will run Magento 1.9 on php 7 , you will get start getting errors.
Today one of our developer got an error while working on largest eCommerce store. And store was built in Magento 1.9.
Error:
Fatal error: Uncaught Error: Function name must be a string in
app\code\core\Mage\Core\Model\Layout.php:555 Stack trace: #0
It happens because in PHP 7 you need to define that you are going to call the $callback variable as a method (function). So, the original line of the code looks like the following (file app/code/core/Mage/Core/Model/Layout.php):
$out .= $this->getBlock($callback[0])->$callback[1]();
In order to make it work on the recent PHP version we need to replace above piece of code by following one:
$out .= $this->getBlock($callback[0])->{$callback[1]}();
Do not forget to clean the cache after all modifications. Also make backup of Layout.php and If you are developer, then you should create a separate extension and override “Mage_Core_Model_Layout” by your own model and make the changes there. You can create new directory : app/code/local/Mage/Core/Model/
Then copy “Layout.php” file there and do all necessary changes in that copied file.
PHP 7 is really fast and good choice if you are running magneto based online store. If you have got with some other magento errors or issues and have suggestions and feedback we will be glad to discuss here.