Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

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

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.

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.

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.

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;
}

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

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.

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

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);
}

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top