Is Magento ready for PHP 7?



PHP 7 is reaching beta status and lots of testing is going on at the moment. Given that Magento caught up within the last year from "runs only on PHP 5.3" to "fully compatible with PHP 5.6", I would like to know how much they are considering PHP 7 compatibility for Magento 1.x as well as Magento 2.

I found this post by Anna Filina where she found one issue in Magento 1.9.1 (still unchanged in 1.9.2), but given that Magento 1 does not have unit tests, I don't trust that this was the only issue.

So the question is: will PHP 7 compatibility for Magento 1 be ensured? And as Magento 2 probably has already been tested on PHP 7 (Thank automated tests!), are there any known issues?

Fabian Schmengler

Posted 2015-07-10T22:35:36.880

Reputation: 49 110

I just tried magento 2.1.2 on php7 and its a no go. – guru1 – 2016-11-10T15:16:19.233

@guru1 Can you elaborate, why? In my experience, it works well. – Fabian Schmengler – 2016-11-10T17:01:44.507

@guru ... I am developing my project in magento 2.1.2 on php 7 and its working fine. What issue you face? – Jai – 2016-11-25T04:23:08.507



Magento announced officially on January 20th, 2016, that CE and EE 2.0.1 officially support PHP 7.0.2.

Magento Enterprise Edition and Community Edition 2.0.1 are now available and feature important security and functional updates, including official support for PHP7.0.2.


Anna Völkl

Posted 2015-07-10T22:35:36.880

Reputation: 14 768


If you are using the most recent version, M CE, there is an extension that will bring it to full PHP 7 compatibility: (Disclaimer: I'm the author, though there is much help from the community.)

It's also installable through Composer from

All incompatibilities mentioned here are fixed. We think there may still be a few edge cases, but nothing show-stopping. Testing, issue reporting and pull requests are welcome.

Ivan Čurdinjaković

Posted 2015-07-10T22:35:36.880

Reputation: 359

it is very bad idea to put some local overrides... – MagenX – 2016-03-15T18:24:29.253

2@MagenX unless you're Inchoo and know what you are doing ;) – 7ochem – 2016-04-13T13:25:20.670

we all do stupid things, time to time..... – MagenX – 2016-04-13T13:46:30.953

2Largest risk with local overrides is using them with incompatible version of magento, from the looks of it author is keeping extension up to date with latest magento version. And if you are on older version of magento, playing with PHP7 is...

Also, blindly following best practices is also stupid, there are situations where it is worth it to "break them". I think it is just one more example of "cargo cult" approach. Btw, extension is awesome :) – grizwako – 2016-04-13T13:54:00.590

The only problem I have here is support of mods. We never know what our clients will want to use when it comes to mods and having to test / upgrade every mod to be php 7 compatible is a nightmare. – Bill Garrison – 2017-07-12T14:25:55.757


No idea about PHP7, but I would guess most of the stuff is still valid in PHP7, you can find more information in the blog of Matthias Geniar

  • ext/mysql: despite it being a very old MySQL extension, I'd reckon it's still very widely used, but it's time everyone moved to pdo_mysql.
  • set_magic_quotes_runtime and magic_quotes_runtime: it seems I've seen these deprecation notices since ... forever?
  • iconv.input_encoding, iconv.output_encoding: so far, I've never had a use for these...
  • # style comments in ini files: hooray for consistency, I've always preferred ; (semicolon) comments in .ini files!
  • preg_replace() eval modifier: hooray for security-minded sysadmins!

I think the only thing we might have in Magento is preg_replace() eval modifier but hopefully not.

Beside this, Magento shipped 1.9.2 with an updated TAF, you can find in dev. With this you should be able to run a bunch of frontend tests on PHP7 and examine the log afterwards

Fabian Blechschmidt

Posted 2015-07-10T22:35:36.880

Reputation: 32 180

2I've been testing Magento 1.9CE on php7 beta, it makes such a huge difference for the admin panel... Catalog tasks etc are so fast. On a 3000 product store, the catalog list admin page went from 12s loading (php5-fpm) to 3.5s (php7-fpm). We're keen to use this in production, so I'm using nginx to route admin url traffic via php7, and keeping front-facing traffic on php5-fpm for now. Excited for php7 release, though :) – Ricky Odin Matthews – 2015-08-07T14:59:36.303

@RickyOdinMatthews How is this working out for you? Still running admin only on php7? Any issues? Could you share the part of the NGINX config that routes admin to php7? – Ottonet – 2016-01-09T09:40:26.457


@Ottonet yes, still using it on admin. I've put my 'default' conf extract here for you

– Ricky Odin Matthews – 2016-01-11T10:59:37.423

1Echoing Fabian's point, your best bet to test is to start with a clean 1.9.2 installation, load the sample data, then run the TAF tests. There will undoubtedly be some things that throw errors or break, and probably even more when you start adding 3rd Party Extensions and any customizations you may have added to your install. Zend had been testing Magento on the PHP 7 release and I would be surprised if there were ANY major issues, though not that there might MANY minor issues. Stock 1.9.2 is the place to start testing.... – Bryan 'BJ' Hoffpauir Jr. – 2015-07-12T05:03:05.470

Good explanation Fabian..thx – Amit Bera – 2015-07-12T14:26:11.500


No comment on Magento 1, but Magento 2 did have some problems with class names like "String". It did not take long to fix, but it did not work out of the box. I expect that Magento 2 will be fixed, but it might not be fixed yet due to other priorities first.

Alan Kent

Posted 2015-07-10T22:35:36.880

Reputation: 2 848

3Current state: class names fixed in develop branch, no more known issues – Fabian Schmengler – 2015-08-09T22:47:01.340


Thans Alan for the info. For reference, this is the Github issue: (still other reserved words such as "object" as it seems)

– Fabian Schmengler – 2015-07-14T15:59:57.670


It is almost ready. I tried running a clean Magento with PHP 7 RC1, which resulted in an instant crash (fatal error) of Magento. After fixing this problem, everything seemed to be working, except the backend, which I was not able log in to. Later it turned out to be a session related problem which can be patched.


  1. The fatal error can be fixed by overriding Mage_Core_Model_Layout then changing line 555 from:
    $out .= $this->getBlock($callback[0])->$callback[1]();
    $out .= $this->getBlock($callback[0])->{$callback[1]}();

  2. The session problem temporarily can be fixed by overriding Mage_Core_Model_Session_Abstract_Varien and rewriting the getData, setData, unsetData, addFullNames methods, so everywhere where $this->_data was used, it will be replaced by $_SESSION.

If someone is interested in the solution, it can be found here.


Posted 2015-07-10T22:35:36.880

Reputation: 511

1Of course someone is interested in the solution ;-) Can you sum up the content of the linked article? There is nothing wrong with linking your blog with additional information, but the answer should be able to stand on its own. – Fabian Schmengler – 2015-09-03T21:51:27.233

Well, the question was whether Magento is ready for PHP 7, not about how to make them work together. Anyhow, I've updated my answer with a brief solution. – Zsolti – 2015-09-04T10:41:44.637


A similar error occurs in Varien_File_Uploader, see

– Fabian Schmengler – 2015-12-09T12:31:23.083

Same for – lrkwz – 2016-02-25T10:58:26.153


Magento2 is ready for PHP 7. Adaptation of code to PHP7 was done and all changes are available in develop branch. See issue on GitHub

Also, support of php 7 in Magento1 require backward incompatible changes and I think will be not supported officially.


Posted 2015-07-10T22:35:36.880

Reputation: 13 549

it's pure amazing that M2 and PHP 7 will be released in same month - November 2015! – FireBear – 2015-09-17T07:52:47.403


There is a problem with how Magento is calculating order grand total, and applying the discounts. This is also stopping the Paypal express checkout, as the line items do not add up to the grand total with the discount.

The problem seems to be that the Mage_Sales_Model_Config_Ordered::_compareTotals() is not working the same in PHP7 as PHP5, and uasort() is now relying on transitive relationship for the ordering, but this does not have to be for order totals.

Try using :-

protected function _getSortedCollectorCodes()
    if (Mage::app()->useCache('config')) {
        $cachedData = Mage::app()->loadCache($this->_collectorsCacheKey);
        if ($cachedData) {
            return unserialize($cachedData);
    $configArray = $this->_modelsConfig;
    // invoke simple sorting if the first element contains the "sort_order" key
    $element = current($configArray);
    if (isset($element['sort_order'])) {
        uasort($configArray, array($this, '_compareSortOrder'));
    } else {
        foreach ($configArray as $code => $data) {
            foreach ($data['before'] as $beforeCode) {
                if (!isset($configArray[$beforeCode])) {
                $configArray[$code]['before'] = array_unique(array_merge(
                    $configArray[$code]['before'], $configArray[$beforeCode]['before']
                $configArray[$beforeCode]['after'] = array_merge(
                    $configArray[$beforeCode]['after'], array($code), $data['after']
                $configArray[$beforeCode]['after'] = array_unique($configArray[$beforeCode]['after']);
            foreach ($data['after'] as $afterCode) {
                if (!isset($configArray[$afterCode])) {
                $configArray[$code]['after'] = array_unique(array_merge(
                    $configArray[$code]['after'], $configArray[$afterCode]['after']
                $configArray[$afterCode]['before'] = array_merge(
                    $configArray[$afterCode]['before'], array($code), $data['before']
                $configArray[$afterCode]['before'] = array_unique($configArray[$afterCode]['before']);
        foreach ($configArray as $code => $data) {
           $largest_small = $smallest_large = 0;
           foreach ($data['after'] as $afterCode) {
              if(isset($configArray[$afterCode]['sort_order']) && $largest_small < $configArray[$afterCode]['sort_order'])
                 $largest_small = $configArray[$afterCode]['sort_order'];
           foreach ($data['before'] as $beforeCode) {
              if(isset($configArray[$beforeCode]['sort_order']) && ($smallest_large == 0 || $configArray[$beforeCode]['sort_order'] < $smallest_large)) 
                 $smallest_large = $configArray[$beforeCode]['sort_order'];
           if($smallest_large <= $largest_small+1){
              if($smallest_large == 0) $smallest_large = $largest_small+1;
              $add = $largest_small+2-$smallest_large;
              foreach ($configArray as $code1 => $data1) {
                 if(!isset($data1['sort_order'])) break;
                 if($smallest_large <= $data1['sort_order'])
                    $configArray[$code1]['sort_order'] += $add;
           $configArray[$code]['sort_order'] = $largest_small+1;
        uasort($configArray, array($this, '_compareSortOrder'));
    $sortedCollectors = array_keys($configArray);
    if (Mage::app()->useCache('config')) {
        Mage::app()->saveCache(serialize($sortedCollectors), $this->_collectorsCacheKey, array(
    return $sortedCollectors;

Dallas Clarke

Posted 2015-07-10T22:35:36.880

Reputation: 639

Excellent, nailed my weird + 20% tax top up on the grand total. – evensis – 2016-03-17T16:20:33.353


This is my research I want to share with you about the magento php7 incompatibilities. Currently I've found some places where the code should fail due to uniform variable syntax.

File: app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Abstract.php

Method: overrideAttribute

$data['filter_options'] = $this->$data['options_method']();

File: app/code/core/Mage/ImportExport/Model/Export/Entity/Customer.php

Method: filterAttributeCollection

$data['filter_options'] = $this->$data['options_method']();

File: app/code/core/Mage/ImportExport/Model/Import/Uploader.php

Method: _validateFile


File: app/code/core/Mage/Catalog/Model/Product/Link/Api/V2.php

Method: assign

if (isset($data->$attribute['code'])) {
    $links[(int)$linkedProductId][$attribute['code']] = $data->$attribute['code'];

File: app/code/core/Mage/Catalog/Model/Product/Link/Api/V2.php

Method: update


File: lib/Varien/File/Uploader.php

Method: _validateFile


File: app/code/core/Mage/Core/Model/Layout.php

Method: getOutput

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


Posted 2015-07-10T22:35:36.880

Reputation: 944


In addition to the other answers related to Magento 1:

A PHP 7 incompatibility in Zend_XmlRpc_Server has been fixed in Zend Framework 1.12.12

All versions prior CE / EE use an older version of Zend Framework, thus might have problems if you use the XML-RPC API of Magento.

Fabian Schmengler

Posted 2015-07-10T22:35:36.880

Reputation: 49 110


Check files from inchoo which are changed to made M1 compatible with php 7, those are minor changes in few files but intelligent work from Inchoo.

Yogesh Trivedi

Posted 2015-07-10T22:35:36.880

Reputation: 1 577


Base URL for project from Inchoo =>

– Fiasco Labs – 2016-08-05T04:34:01.093


I'm using Magento 2 CE Version 2.1.4 & Works fine.


if (!defined('PHP_VERSION_ID') || !(PHP_VERSION_ID >= 50005 && PHP_VERSION_ID < 50700 || PHP_VERSION_ID === 70002 || PHP_VERSION_ID === 70004 || PHP_VERSION_ID >= 70006)) {
    if (PHP_SAPI == 'cli') {
        echo 'Magento supports PHP 5.6.5, 7.0.2, 7.0.4 and 7.0.6 or later. ' .
            'Please read';
    } else {
        echo <<<HTML
<div style="font:12px/1.35em arial, helvetica, sans-serif;">
    <p>Magento supports PHP 5.6.5, 7.0.2, 7.0.4 and 7.0.6 or later. Please read
    <a target="_blank" href="">
    Magento System Requirements</a>.

Ankit Shah

Posted 2015-07-10T22:35:36.880

Reputation: 3 685


Short answer is no, it doesn't. Magento CE only supports PHP 5.4 and 5.5 officially. And while PHP 5.6 runs it just fine, it saturates log files with multitudes of warning messages.

Long answer is that it's relatively easy to modify it to run support PHP7. However many extensions are still not PHP7 compatible so you're largely on your own.

Sheshgiri Anvekar

Posted 2015-07-10T22:35:36.880

Reputation: 579