Magento 1.9 on PHP7

May 30th, 2015

I tested many applications on PHP7 and only one of them had an issue: Magento 1.9. The issue was very easy to fix. I couldn't find a way to submit a patch because only Magento 2 was on GitHub, so here's the patch if you decide to upgrade.

File: app/code/core/Mage/Core/Model/Layout.php
Inside function getOutput(), change this line:

$out .= $this->getBlock($callback[0])->$callback[1]();

to this:

$fname = $callback[1];
$out .= $this->getBlock($callback[0])->$fname();

If you're interested to learn more about why this happens, read about the new Uniform Variable Syntax.

Update Nikita Popov suggested that you can even do this in 1 line like so:

$this->getBlock($callback[0])->{$callback[1]}();

Previous: Conference Travel Expenses Next: Composer Security Checker