title: Error in preg_replace () → preg_replace_callback () rewriting? [Smarty_Compiler.class.php]
body: <p>After upgrading PHP to version 7, Warning appeared in Smarty_Compiler.class.php.</p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>Looking at the error location ...... ↓</p>
  
  <pre><code>$source_content = preg_replace($search.'e', "'"
                                     . $this-&gt;_quote_replace($this-&gt;left_delimiter) . 'php'
                                     . "' . str_repeat(\"\n\", substr_count('\\0', \"\n\")) .'"
                                     . $this-&gt;_quote_replace($this-&gt;right_delimiter)
                                     . "'"
                                     , $source_content);
  </code></pre>
  
  <p>Preg_replace () seemed to be unusable, and I changed it to preg_replace_callback ().</p>
  
  <pre><code>$source_content = preg_replace_callback($search
                                     , function($matches) {
                                           return  "'" 
                                                  . $this-&gt;_quote_replace($this-&gt;left_delimiter) . 'php'
                                                  . "' . str_repeat(\"\n\", substr_count('" . $matches[0] . "', \"\n\")) .'"
                                                  . $this-&gt;_quote_replace($this-&gt;right_delimiter)
                                                  . "'";
                                       }
                                     , $source_content);
  </code></pre>
  
  <p>Then, Smarty error appeared this time ... ....</p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>In the place where the error occurred, the version information is commented out.
  Before upgrading PHP it worked properly, so I think that I made mistakes in preg_replace_callback () rewriting, but I do not know where wrong ...
  Also, I'm not sure what this process of Smarty_Compiler.class.php is doing...
  If you are familiar with PHP or Smarty, please let me know.</p>