Magento on PHP 7 – a speed demon?

Magento on PHP 7 – a speed demon?


Written in PHP, Magento is one of the best e-commerce platforms around. When it first appeared in 2008, the PHP version was 5.2. Now on Magento 1.9 supports PHP versions up to 5.6 (although unofficially). We’re now onto Magento 2, finally released – awesome news. This also means that the original Magento will lose support soon, but that doesn’t mean people will stop using it. In addition, we’re also moving to PHP v7. V7 is, by all accounts, twice as fast. Exciting!

Magento 1.9 will not work with PHP v7 out of the box, but there are some easy fixes for this to make it compatible (as ever, try this out on a staging version before you go live!). Let’s say you’ve installed the latest version of PHP. It was released on the 3rd December, so if not, get on it!

Trying to load a Magento page, you will get the following error.
1 Fatal error: Uncaught Error: Function name must be a string in app/code/core/Mage/Core/Model/Layout.php:555

This is because you need to clarify the `$callback` variable will be called as a method (function). The original bit of code was:
(file app/code/core/Mage/Core/Model/Layout.php)

Now you need to replace it with this
1 $out .= $this->getBlock($callback[0])->{$callback[1]}();

Don’t edit the files directly – instead create a separate extension which overrides Mage_Core_Model_Layout with your own model. If that isn’t to taste, try creating a new directory:
1 app/code/local/Mage/Core/Model/

Copy Layout.php there, making the necessary changes. You’ll need to clear the cache after any edits. This should mean you can now load your Magento pages.

Now you should have a super fast Magento installation. Upgrading to PHP 7 is worth doing, and worth doing yesterday!