【问题标题】:Magento 1.7: Strict Notice warning after SUPEE-10975 security patchMagento 1.7:SUPEE-10975 安全补丁后的严格通知警告
【发布时间】:2018-11-29 10:35:37
【问题描述】:

在 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 的回归还是我的安装问题?

【问题讨论】:

    标签: php magento magento-1.7


    【解决方案1】:

    更新: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 将自动返回使用核心文件,尽管有严格模式通知。

    唯一的问题是……

    我们正在制造技术债务

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

    【讨论】:

    • 值得注意的是,1.7的SUPEE-11219补丁似乎修复了这个bug,所以在应用11219后,本地覆盖文件可能会被删除。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多