php - Magento 1.7 : Strict Notice warning after SUPEE-10975 security patch

标签 php magento magento-1.7

在 Magento 1.7.0.2 中安装 SUPEE-10975 后,我收到此 PHP 通知:

Strict Notice: Declaration of Mage_Core_Controller_Request_Http::getBaseUrl() should be compatible with that of Zend_Controller_Request_Http::getBaseUrl()  in app/code/core/Mage/Core/Controller/Request/Http.php on line 36

#0 app/code/core/Mage/Core/Controller/Request/Http.php(36): mageCoreErrorHandler(2048, 'Declaration of ...', '/kunden/12345_8...', 36, Array)
#1 lib/Varien/Autoload.php(93): include('/kunden/12345_8...')
#2 [internal function]: Varien_Autoload->autoload('Mage_Core_Contr...')
#3 app/code/core/Mage/Core/Model/App.php(1219): spl_autoload_call('Mage_Core_Contr...')
#4 app/code/core/Mage/Core/Model/Cookie.php(83): Mage_Core_Model_App->getRequest()
#5 app/code/core/Mage/Core/Model/Cookie.php(273): Mage_Core_Model_Cookie->_getRequest()
#6 app/code/core/Mage/Core/Model/App.php(568): Mage_Core_Model_Cookie->get()
#7 app/code/core/Mage/Core/Model/App.php(488): Mage_Core_Model_App->_checkCookieStore('website')
#8 app/code/core/Mage/Core/Model/App.php(349): Mage_Core_Model_App->_initCurrentStore('', 'store')
#9 app/Mage.php(683): Mage_Core_Model_App->run(Array)
#10 index.php(87): Mage::run('', 'store')
#11 {main}

在我的安装中好像有两次可用的代码:

  • app/code/core/Zend/Controller/Request/Http.php => 引入 SUPEE-10975
  • lib/Zend/Controller/Request/Http.php => Magento 1.7.0.2 基础安装包中可用

这是 SUPEE-10975 的回归还是我安装的问题?

最佳答案

更新:SUPEE-11219 似乎解决了这个问题,所以我下面的修复可能会在应用 11219 补丁后被删除

原答案:

我见过同样的问题,它看起来确实像是 1.7 的 SUPEE-10975 补丁中的回归。

更改您的 PHP 配置以抑制严格模式通知会让您工作,但如果您更喜欢在严格模式下工作,也有一种方法可以打补丁。

正如您所观察到的,SUPEE-10975 添加了一个新类 Mage_Core_Controller_Request_Http,它扩展了新捆绑的 Zend 类 Zend_Controller_Request_Http,位于新文件 app/code/core/Zend/Controller/Request/Http.php.

发出严格模式通知是因为 Mage_Core_Controller_Request_Http::getBaseUrl() 方法签名与新的 Zend_Controller_Request_Http::getBaseUrl() 方法签名不正确匹配它扩展了。

Mage_Core_Controller_Request_Http::getBaseUrl()

class Mage_Core_Controller_Request_Http extends Zend_Controller_Request_Http
...
public function getBaseUrl() //getBaseUrl has no parameters here
{
    ...
}

Zend_Controller_Request_Http::getBaseUrl()

class Zend_Controller_Request_Http extends Zend_Controller_Request_Abstract
...
public function getBaseUrl($raw = false) //getBaseUrl in the ancestor class has the parameter $raw
{
    ...
}

Mage_Core_Controller_Request_Http::getBaseUrl() 方法应该有一个参数 $raw 以避免严格模式通知。这并不是一个真正的错误,PHP 可以解决它,但理想情况下应该更正它。

重新出发

在您的 PHP 配置中抑制严格模式通知允许代码忽略此错误,但如果代码可以在严格模式下运行会更好,不是吗?

这里是修复它的方法,以便它在严格模式下运行

复制app/code/core/Mage/Core/Controller/Request/Http.php到本地代码池:app/code/local/Mage/Core/Controller/Request/Http.php(请注意,我们正在 local 文件夹中创建覆盖)

编辑 app/code/local/Mage/Core/Controller/Request/Http.php 并更改第 265 行

public function getBaseUrl()

public function getBaseUrl($raw = false)

如果您的代码已编译,并且编译器运行时没有出错,您可能需要清除编译版本才能看到您的更改。 从 Magento 的 webroot 发出命令 php shell/compiler.php clear

商店现在应该正常运行,应用了 SUPEE-10975 补丁。

这是做什么的

我们在本地代码文件夹中创建一个核心 Magento 文件的副本,Magento 会在使用核心文件之前尝试文件的本地副本,因此这个本地副本会覆盖原始文件。

我们对文件进行编辑,使 getBaseUrl 的方法签名与祖先类匹配,从而抑制严格模式通知。

这样做是可以的,因为无论如何 Magento 1.7 代码都没有使用 $raw 参数,并且该方法的默认行为将与没有参数时完全相同。

要撤消此更改,只需删除我们刚刚创建的本地副本 app/code/local/Mage/Core/Controller/Request/Http.php . Magento 将自动返回使用核心文件,尽管有严格模式通知。

唯一的问题是...

我们正在创造技术债务

下次进行安全补丁或升级时,如果原始文件发生更改,我们制作的本地副本将不会得到补丁或更新。您需要检查是否仍需要进行此更改,如果需要,请将核心文件重新复制到本地文件夹并按上述方式重新修补该文件。

关于php - Magento 1.7 : Strict Notice warning after SUPEE-10975 security patch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53537025/

相关文章:

php - fatal error : Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes)

php - 为什么在 laravel 中使用 npm?

Magento 产品系列 选择所有属性

php - 在 magento 中以编程方式创建可配置产品

php - 在 PHP 脚本中删除双引号的 SQL 查询不起作用

php通过socket编程传递c结构数据

magento - 将 php 代码添加到静态 block

magento - 如何在magento中调用另一个 Action ?

php - 如何加快Magento网站?

magento - 在magento中显示交货时间