Filina Consulting

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:



Donato May 30th, 2015 Hi. Did you tried enclosing the variable inside braces?
Tim Bezhashvyly May 31st, 2015 Another issue is `iconv_set_encoding` but this is also quite easy to fix.
Melvyn Sopacua May 31st, 2015 Encoding fixes you already need for 5.6 in developer mode at least. Which begs the question, was this test with or without developer mode enabled?
Anna May 31st, 2015 I tested without dev mode.
John June 23rd, 2015 Can you log In into admin area?
I have an issue according to redirecting after submit Login button to the: index/noRoute/key/

magento 1.9.1
PHP 7.0.0-dev (fpm-fcgi) (built: Jun 21 2015 00:40:57)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies
Craig Carnell July 27th, 2015 Hi John,

I have the same issue unable to login to the back end (admin). Works fine on php 5.6. Any clues?
Anna July 27th, 2015 I'll have to retest that when I have some time.
John August 2nd, 2015 After lost lot of time, I have only an unfair way:
1. step: restart nginx/apache with php v.5* mode
2. step: login into magento area
3. step: restart nginx/apache with php v.7 mode
So: admin area worked like a charm
Craig Carnell August 10th, 2015 Thanks for the suggestion, but that's not really a long term solution :(
Detzler August 13th, 2015 Wazzup? Any Updates to the admin-login dilemma?
Detzler August 13th, 2015 app/code/core/Mage/Admin/Model/Session.php:120

uncommenting $this->renewSession(); solves the problem

But why? Any idea?
Craig Carnell August 25th, 2015 It doesn't work in PHP 7.0 RC1 and they do not appear to listen to their own bug tracker. Any ideas how to fix the admin login issue? Thanks
hpvd October 19th, 2015 see
In PHP 7 RC3 the session-related problem has been solved, so the only thing you need is to fix Layout.php. November 8th, 2015 Here's a patch to make things easier:

PHP7 Magento 1.9 core patch November 8th, 2015 ...or an extension if you don't want to edit core files:

PhpSeven Magento Extension, a compatibility module to get Magento 1.9.* working with >= PHP 7.0.0 RC 6
chris November 24th, 2015 Under php7 discount codes are not working properly. If you apply a code, you can see the right amount deducted near sub-total but Grand Total ignores it (grand total amount is just the same). Could be a big problem with customers.
Henning December 8th, 2015 Thanks for this post, now I could test Magento with PHP7
Darren December 17th, 2015 Can confirm this issue as well. Were you able to find a fix Chris?
Reini December 20th, 2015 There are at least two more issues:

1. Product image upload results in http error:

2. Wrong tax calculation in cart:
Unfortunatly i havent found any solution yet, it would be great if someone could solve this.
Praful January 19th, 2016 This solution work for me.
Great!!! Thank you!!
Bart June 14th, 2016 Any fix?
Begrezen June 23rd, 2016 Hi, I've got same problem with this

When debugging found that collectors in Mage_Sales_Model_Config_Ordered are sorted wrong in php7.
Found this topic:

so, the method uasort() works different in php7, so we need to emulate old uasort and it will work again.

Mage_Sales_Model_Config_Ordered lines:
142 and 170 (magento 1.8.1)
Begrezen June 23rd, 2016 hmmm seams that you don't have to change this method, just "repair" the before and after values for quote totals.

In \app\code\core\Mage\Sales\etc\config.xml you can find , just need to precise and better.

The solution is presented here:

I'll try it now and check if it helpes.
Sam September 8th, 2016 Admin login issue fixed by commenting below line -


commenting $this->renewSession(); solves the problem.

Thanks @Detzler.
Joshua September 14th, 2016 These guys solved it for me.
Kelvin Kyaw October 27th, 2016 Today (27-Oct-2016 9:55AM Singapore Time), I tried to test Magento 1.9.2 on PHP 7.

Here my initial problems with php 7.

1) Admin Login redirect login page (solved by comment $this->renewSession(); )
2) Customer cannot create (Decoding Error in Zend_Json::decode()) function
3) Tax Calculation (refernece on top comments)
4) Coupon code calculation (refernece on top comments)
5) And a lot more

So, I realized that all these solution are not sustainable way with php 7 and Magento 1x

My personal recommendation -

Downgrade to PHP5.6. Bad news is 1x slower than PHP 7.
Spencer November 2nd, 2016 This is a very simple change that Magento is bound to accept. I'll try to find out how to get something like this upstream. Also, will you marry me? :-P
Anon May 3rd, 2017 I can't tell you how irritating it is for a so called "experienced developer" to be telling others to modify the core. You could have told people to copy the file from core to local and modified it there. Pure laziness and irresponsible.

It's real experienced developers who get left with mess that people like you leave behind. August 13th, 2017 Excelente Anna. Funciona a la perfección
Jorge November 30th, 2017 Awsome !! Perfect solution....
tolikkk February 4th, 2018 Hello.

This page is protected by reCAPTCHA and the Google
Privacy Policy and Terms of Service apply.

Twitter: @afilina | E-mail: