PHP 5.5 버그-더 이상 사용되지 않는 기능 : preg_replace ()


16

PHP 5.5로 업그레이드 한 후 웹 사이트, 상점 또는 상점보기를 추가 할 때 다음 오류가 발생합니다. 이 버그는 여전히 Magento 1.9.0.1에 있습니다.

Exception message: Deprecated functionality: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in app/code/core/Mage/Core/Helper/Abstract.php on line 238
Trace: #0 [internal function]: mageCoreErrorHandler(8192, 'preg_replace():...', 'app...', 238, Array)
#1 app/code/core/Mage/Core/Helper/Abstract.php(238): preg_replace('# <(?![/a-z]) |...', 'htmlentities('$...', 'New Store Name')
#2 app/code/core/Mage/Adminhtml/controllers/System/StoreController.php(175): Mage_Core_Helper_Abstract->removeTags('New Store Name')
#3 app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Adminhtml_System_StoreController->saveAction()
#4 app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('save')
#5 app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#6 app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#7 app/Mage.php(686): Mage_Core_Model_App->run(Array)
#8 index.php(87): Mage::run('', 'store')
#9 {main}

이것은 오류를 일으키는 코드입니다

코드는 다음에서 찾을 수 있습니다 Mage_Core_Helper_Abstract

/**
 * Remove html tags, but leave "<" and ">" signs
 *
 * @param   string $html
 * @return  string
 */
public function removeTags($html)
{
    $html = preg_replace("# <(?![/a-z]) | (?<=\s)>(?![a-z]) #exi", "htmlentities('$0')", $html);
    $html =  strip_tags($html);
    return htmlspecialchars_decode($html);
}

내 생각에 이것은 방법에 대한 가장 쉬운 패치입니다.

/**
 * Remove html tags, but leave "<" and ">" signs
 *
 * @param   string $html
 * @return  string
 */
public function removeTags($html)
{
    $html = preg_replace_callback("# <(?![/a-z]) | (?<=\s)>(?![a-z]) #xi",
        create_function('$matches', 'return htmlentities($matches);'),
        $html
    );
    $html =  strip_tags($html);
    return htmlspecialchars_decode($html);
}

이 방법은에 의해서만 사용됩니다 Mage_Adminhtml_System_StoreController::storeAction().

이 문제를 해결할 수있는 장소는 세 가지가 있습니다.

  1. Mage_Core_Helper_Abstract => 메소드가있는 곳이지만 코어 파일을 만지기 때문에 짜증납니다.
  2. Mage_Core_Helper_Abstract => 다시 작성하십시오. 추상 클래스이므로 다시 작성할 수 없습니다.
  3. Mage_Adminhtml_Helper_Data를 다시 작성하고 거기에 메소드를 추가하십시오. => 나는 이것이 갈 길이라고 생각합니다.

너희들은 어떻게 생각하니?

  1. 옵션 # 3이 문제를 해결하는 올바른 방법입니까?
  2. 패치의 코드가 정확합니까?

1.9.1 CE 및 1.14.1 EE 문제

답변:


13

그래 당신 말이 맞아요. 관리 HTML 도우미를 수정하십시오. 이것은 내가 사용하는 수정의 차이점입니다.

--- app/code/core/Mage/Core/Helper/Abstract.php.orig 2014-09-25 15:32:56.000000000 +0200
+++ app/code/core/Mage/Core/Helper/Abstract.php 2014-09-25 15:34:42.000000000 +0200
@@ -235,7 +235,9 @@
  */
 public function removeTags($html)
 {
-        $html = preg_replace("# <(?![/a-z]) | (?<=\s)>(?![a-z]) #exi", "htmlentities('$0')", $html);
+        $html = preg_replace_callback("# <(?![/a-z]) | (?<=\s)>(?![a-z]) #xi", function($matches) {
+            return htmlentities($matches[0]);
+        }, $html);
         $html =  strip_tags($html);
         return htmlspecialchars_decode($html);
 }

이것은 동작이 PHP 5.4와 동일한 지 확인하는 테스트입니다.

<?php

namespace Vinai\Kopp\Magento\Tests;

class MageAdminhtmlHelperDataTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var \Mage_Adminhtml_Helper_Data
     */
    private $helper;

    static public function setUpBeforeClass()
    {
        ini_set('display_errors', 1);
        umask(0);
        error_reporting(E_ALL);
        require_once 'app/Mage.php';
        \Mage::setIsDeveloperMode(true);
    }

    public function setUp()
    {
        $this->helper = new \Mage_Adminhtml_Helper_Data();
    }

    /**
     * @covers \Mage_Core_Helper_Abstract::removeTags
     * @dataProvider removeTagsDataProvider
     */
    public function testRemoveTags($inputHtml, $expected)
    {
        $result = $this->helper->removeTags($inputHtml);
        $this->assertEquals($expected, $result);
    }

    public function removeTagsDataProvider()
    {
        return array(
            array('<b>', ''),
            array('<b> >', ' >'),
            array('<b> <', ' <'),
            array('<b/> </', ' '),
            array('< <b/>', '< '),
            array('> <b/>', '> '),
            array('</ <b/>', ''),
            array('x />', 'x />'),
            array('> <', '> <'),
            array('>>', '>>'),
            array('<<', '<<'),
            array('<>', '<>'),
        );
    }
} 

4

이것은 이제 Magento EE 1.14.1 및 1.9.1에서 수정되었습니다. 추가 비 호환성은 pack () / unpack () 변경으로, 설치 중에 백업 / 롤백 및 일부 확장 (tar 파일에 닿는 모든 확장)에 영향을줍니다. 프로덕션에서 Magento를 실행하는 사람은 사용하지 않는 것으로 가정합니다.


패치가 이전 버전 용으로 출시 될 때;)
— Ben Lessani-Sonassi

아직 / 언제 모르겠다
— Piotr Kaminski

3

짧은 대답 : Magento는 PHP 5.5와 호환되지 않으므로 웹 서버를 5.5로 업데이트하지 마십시오.

더 긴 대답 : Magento는 다음 버그 로이 버그를 수정한다고 가정하므로 핵심 핵을 만들고 최선을 다할 것입니다. 코드가 올바른지 모르겠습니다. 죄송합니다.


안녕 Fabian, 우리는 지금 꽤 오랫동안 PHP 5.5에서 모든 서버를 운영하고 있습니다. 이것은 내가 만난 첫 번째 문제입니다. 알려진 다른 비 호환성 또는이 정보의 출처는 무엇입니까?
— RobM84

1
나는 모른다. 변경 로그 php.net/manual/en/migration54.php 와 grep에서 메소드와 ini 설정을 확인할 수 있습니다
— Fabian Blechschmidt

1
실제로 이것은 magento CE에서 유일한 PHP 5.5 문제입니다. 지난 반년 동안 또 다른 문제는 발생하지 않았습니다.
— Flyingmana

2
또한 5.3은 오래된 구식이므로 PHP 5.4는 대부분의 사람들이 APC와 함께 사용할 때 실제 안정적인 상태에 도달하지 않습니다. 5.5는 현재 유일하게 안정적인 최소 지원 PHP 버전입니다. 이전 PHP 버전에 포함
— Flyingmana
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.