2017-09-12 11 views
0

PHPをバージョン7にアップグレードした後、警告がSmarty_Compiler.class.phpに表示されました。エラー位置を見てみるとpreg_replace()→preg_replace_callback()の書き換えにエラーがありますか? [Smarty_Compiler.class.php]

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /var/www/……/Smarty/Smarty_Compiler.class.php on line 271

......↓

$source_content = preg_replace($search.'e', "'" 
            . $this->_quote_replace($this->left_delimiter) . 'php' 
            . "' . str_repeat(\"\n\", substr_count('\\0', \"\n\")) .'" 
            . $this->_quote_replace($this->right_delimiter) 
            . "'" 
            , $source_content); 

にpreg_replace()は使用できないように見えた、と私はそれがpreg_replace_callbackに変更さ()。

$source_content = preg_replace_callback($search 
            , function($matches) { 
             return "'" 
               . $this->_quote_replace($this->left_delimiter) . 'php' 
               . "' . str_repeat(\"\n\", substr_count('" . $matches[0] . "', \"\n\")) .'" 
               . $this->_quote_replace($this->right_delimiter) 
               . "'"; 
            } 
            , $source_content); 

Smartyのエラーはエラーが発生した場所では

Fatal error: Smarty error: [in PATH]: syntax error: unrecognized tag: php' . str_repeat(" ", substr_count('{*version {$ZEND_VERSION (Smarty_Compiler.class.php, line 458) in /var/www/……/Smarty/Smarty.class.php on line 1095

... ....今回登場その後、バージョン情報がコメントアウトされています。 PHPをアップグレードする前に、正しく動作していたので、preg_replace_callback()の書き換えに間違いがあったと思いますが、どこが間違っているのか分かりません... また、Smarty_Compiler.class.phpのこのプロセスが何をしているのかよくわかりません... PHPやSmartyに精通している方は、私にお知らせください。

+0

を試すには、 'str_repeat'を引用しないでください。 – chris85

答えて

1

Smartyはテンプレートエンジンであり、ライブラリであり、コード自体を変更するべきではありません。代わりに、使用しているバージョンを最新のバージョンにアップグレードしてください。それはPHP7をサポートしているようだ。

+1

バージョンを調べると、Smarty 2.6、 3シリーズにアップグレードします。 ありがとうございます! – Gura

0

この

$source_content = preg_replace_callback($search, 
     function($matches) { 
      return 
       $this->_quote_replace($this->left_delimiter) . 'php' . str_repeat(
        $this->_quote_replace("\n"), 
        substr_count($matches[0], $this->_quote_replace("\n")) 
       ) 
       . $this->_quote_replace($this->right_delimiter); 
      }, 
      $source_content 
    ); 
関連する問題