71

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?

  • I just tried magento 2.1.2 on php7 and its a no go. – guru1 Nov 10 '16 at 15:16
  • @guru1 Can you elaborate, why? In my experience, it works well. – Fabian Schmengler Nov 10 '16 at 17:01
  • @guru ... I am developing my project in magento 2.1.2 on php 7 and its working fine. What issue you face? – Jai Nov 25 '16 at 4:23

13 Answers 13

29

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.

Link: https://magento.com/blog/technical/new-magento-20-resources-and-support-php7

26

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

It's also installable through Composer from http://packages.firegento.com/.

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.

  • it is very bad idea to put some local overrides... – MagenX Mar 15 '16 at 18:24
  • 2
    @MagenX unless you're Inchoo and know what you are doing ;) – 7ochem Apr 13 '16 at 13:25
  • we all do stupid things, time to time..... – MagenX Apr 13 '16 at 13:46
  • 2
    Largest 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 Apr 13 '16 at 13:54
  • 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 Jul 12 '17 at 14:25
21

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

  • 1
    Echoing 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. Jul 12 '15 at 5:03
  • Good explanation Fabian..thx – Amit Bera Jul 12 '15 at 14:26
  • 2
    I'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 Aug 7 '15 at 14:59
  • @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 Jan 9 '16 at 9:40
  • 1
    @Ottonet yes, still using it on admin. I've put my 'default' conf extract here for you pastebin.com/9z1U94ug – Ricky Odin Matthews Jan 11 '16 at 10:59
13

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.

10

It is almost ready. I tried running a clean Magento 1.9.2.1 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.

Briefly:

  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]();
    into
    $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.

  • 1
    Of 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 Sep 3 '15 at 21:51
  • 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 Sep 4 '15 at 10:41
  • 1
    A similar error occurs in Varien_File_Uploader, see magento.stackexchange.com/questions/93066/… – Fabian Schmengler Dec 9 '15 at 12:31
  • Same for 1.9.2.4 – lrkwz Feb 25 '16 at 10:58
8

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.

  • it's pure amazing that M2 and PHP 7 will be released in same month - November 2015! – FireBear Sep 17 '15 at 7:52
7

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
    reset($configArray);
    $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])) {
                    continue;
                }
                $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])) {
                    continue;
                }
                $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(
                Mage_Core_Model_Config::CACHE_TAG
            )
        );
    }
    return $sortedCollectors;
}
  • Excellent, nailed my weird + 20% tax top up on the grand total. – evensis Mar 17 '16 at 16:20
6

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

$params['object']->$params['method']($filePath);

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

$data->$attribute['code']

File: lib/Varien/File/Uploader.php

Method: _validateFile

$params['object']->$params['method']($this->_file['tmp_name']);

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

Method: getOutput

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

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 1.9.2.2 / EE 1.14.2.2 use an older version of Zend Framework, thus might have problems if you use the XML-RPC API of Magento.

1

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. https://github.com/Inchoo/Inchoo_PHP7/tree/master/app/code/local/Inchoo/PHP7

1

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

magento\app\bootstrap.php

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 http://devdocs.magento.com/guides/v1.0/install-gde/system-requirements.html';
    } 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="http://devdocs.magento.com/guides/v1.0/install-gde/system-requirements.html">
    Magento System Requirements</a>.
</div>
HTML;
    }
    exit(1);
}
1

Short answer is no, it doesn't. Magento CE 1.9.2.4 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.

0

PHP 7.0 is End of life as of the first week of December 2018.

As of this post, the current version of Magento 2.2.3 (February 20, 2018 release) does not support PHP 7.1, or PHP 7.2.

You can confirm the supported versions by checking app/bootstrap.php in your Magento install folder, and look for code similar to the following:

/* PHP version validation */
if (!defined('PHP_VERSION_ID') || !(PHP_VERSION_ID === 70002 || PHP_VERSION_ID === 70004 || PHP_VERSION_ID >= 70006)) {
    if (PHP_SAPI == 'cli') {
        echo 'Magento supports 7.0.2, 7.0.4, and 7.0.6 or later. ' .
            'Please read http://devdocs.magento.com/guides/v1.0/install-gde/system-requirements.html';
    } else {
        echo <<<HTML
<div style="font:12px/1.35em arial, helvetica, sans-serif;">
    <p>Magento supports PHP 7.0.2, 7.0.4, and 7.0.6 or later. Please read
    <a target="_blank" href="http://devdocs.magento.com/guides/v1.0/install-gde/system-requirements.html">
    Magento System Requirements</a>.
</div>
HTML;
    }
    exit(1);
}

There also seems to be issues in .htaccess which cause 500 errors with apache 2.4.

Additionally, the composer file included only contains dependencies for php5.5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.