Magento 准备好支持 PHP 7 了吗?
-
13-12-2019 - |
题
PHP 7 已达到 Beta 状态,目前正在进行大量测试。鉴于 Magento 在去年从“仅在 PHP 5.3 上运行”到“完全兼容 PHP 5.6”,我想知道他们在多大程度上考虑 Magento 1.x 和 Magento 2 的 PHP 7 兼容性。
我发现 安娜·菲利娜的这篇文章 她在 Magento 1.9.1 中发现了一个问题(在 1.9.2 中仍然没有变化),但考虑到 Magento 1 没有单元测试,我不认为这是唯一的问题。
所以问题是:能否确保 PHP 7 对 Magento 1 的兼容性?由于 Magento 2 可能已经在 PHP 7 上进行了测试(感谢自动化测试!),是否有任何已知问题?
解决方案
洋养碟在2016年1月20日正式宣布,CE和EE 2.0.1正式支持PHP 7.0.2。
Magento Enterprise Edition和Community Edition 2.0.1现在是 可用并具有重要的安全性和功能更新, 包括对PHP7.0.2的官方支持。
链接: https://magento.com/blog/technical/new-magento-20-companess-and-support-php7
其他提示
如果您使用的是最新版本,M CE 1.9.2.2,则会将其带到完整的PHP 7兼容性:https://github.com/inchoo/inchoo_php7 。(免责声明:我是作者,虽然社区有很多帮助。)
它也可以通过 http://packages.firegento.com/ 。
此处提到的所有不兼容都是固定的。我们认为可能还有一些边缘案例,但没有任何展示停止。欢迎测试,发行报告和拉拔请求。
不知道php7,但我会猜测大多数东西在php7中仍然有效,可以在 matthias geniar
我认为我们在Magento中可能拥有的唯一可能是
- ext / mysql:尽管它是一个非常古老的mysql扩展,但我估计它仍然非常广泛,但它是每个人都移动到pdo_mysql的时候了。
set_magic_quotes_runtime
和magic_quotes_runtime
:似乎我已经看到了这些弃用通知以来......永远?iconv.input_encoding
,iconv.output_encoding
:到目前为止,我从未有过这些...#
风格在INI文件中的评论: hooray进行一致性,我一直都喜欢; (分号)在.ini文件中注释!preg_replace()
eval修饰符: hooray用于安全志同道德的sysadmins!
preg_replace()
eval修饰符但希望没有。
在此旁边,Magento发货1.9.2使用更新的TAF,您可以在DEV中找到。使用此,您应该能够在PHP7上运行一堆前端测试,然后检查日志
对magento 1没有评论,但Magento 2确实有一些类别与“string”这样的类名。它没有长时间修复,但它没有开箱即用。我希望Magento 2将是固定的,但它可能不是由于其他优先事项而定制的。
快准备好了。我尝试使用 PHP 7 RC1 运行干净的 Magento 1.9.2.1,这导致 Magento 立即崩溃(致命错误)。解决这个问题后,一切似乎都正常,除了后端,我无法登录。后来发现这是一个与会话相关的问题,可以修复。
简要地:
致命错误可以通过覆盖来修复
Mage_Core_Model_Layout
然后将第 555 行更改为:
$out .= $this->getBlock($callback[0])->$callback[1]();
进入
$out .= $this->getBlock($callback[0])->{$callback[1]}();
会话问题可以通过覆盖暂时解决
Mage_Core_Model_Session_Abstract_Varien
并重写getData
,setData
,unsetData
,addFullNames
方法,所以无处不在$this->_data
已使用,它将被替换为$_SESSION
.
如果有人对解决方案感兴趣,可以找到 这里.
Magento2已准备好用于PHP 7.已完成代码对PHP7的调整,并且所有更改都可以在Develop Branch中获得。在 github
上查看问题 此外,Magento1中PHP 7的支持需要落后不兼容的变化,我认为将不正式支持。玛托如何计算宏伟总数,并应用折扣。这也在停止PayPal Express结账,因为线条物品不会加入宏伟的总量。
问题似乎是PhP7中的Mage_Sales_Model_Config_Ordered::_compareTotals()
在PHP5中没有与PHP5相同的工作,并且世代odicetagcode现在依赖于订购的传递关系,但这不必是订单总数。
尝试使用: -
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;
}
. 这是我的研究,我想与您分享Magento PHP7的不兼容。目前,由于变量语法统一,我发现了一些代码应该失败的地方。
文件:app / code / core / mage / importexport / model / Expority / Product /类型/ Abstract.php
方法:覆盖覆盖
$data['filter_options'] = $this->$data['options_method']();
.
文件:app / code / core / mage / importexport / model / Exportity / Customer.php
方法:filterattributecollection
$data['filter_options'] = $this->$data['options_method']();
.
文件:app / code / core / mage / importexport / model / model / uploader.php
方法:_validatefile
$params['object']->$params['method']($filePath);
.
文件:app / code / core / mage /目录/型号/产品/链接/ api / v2.php
方法:分配
if (isset($data->$attribute['code'])) {
$links[(int)$linkedProductId][$attribute['code']] = $data->$attribute['code'];
}
.
文件:app / code / core / mage /目录/型号/产品/链接/ api / v2.php
方法:更新
$data->$attribute['code']
.
文件:lib / varien / file / houseoder.php
方法:_validatefile
$params['object']->$params['method']($this->_file['tmp_name']);
.
文件:app / code / core / mage / core / model / layout.php
方法:getoutput
$out .= $this->getBlock($callback[0])->$callback[1]();
. 从inchoo中检查文件,这些文件被更改为使m1与php 7兼容,这些文件很少有更改,但智能工作来自inchoo。 https://github.com/inchoo_php7/tree/ master / app / code / local / inchoo / php7
我正在使用magento 2 ce版本2.1.4&工作正常。
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);
}
. 短答案是否定,它没有。Magento CE 1.9.2.4仅支持PHP 5.4和5.5正式。虽然PHP 5.6运行它只是很好,但它会使日志文件饱和具有多点警告消息。
长答案是修改它运行支持PHP7相对容易。然而,许多扩展仍然不是PHP7兼容,所以你很大程度上是你自己的。
PHP 7.0 已于 2018 年 12 月第一周终止生命周期。
截至本文发布,当前版本的 Magento 2.2.3(2018 年 2 月 20 日发布)不支持 PHP 7.1 或 PHP 7.2。
您可以通过检查来确认支持的版本 app/bootstrap.php
在 Magento 安装文件夹中,查找类似于以下内容的代码:
/* 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);
}
似乎也存在问题 .htaccess
这会导致 apache 2.4 出现 500 错误。
此外,包含的 Composer 文件仅包含 php5.5 的依赖项