Error with preg_replace() and modifier "e" in Smarty 2.6.0 on PHP 5.5.3 [SOLVED]

The PHP Template Engine: Smarty 2.6.0 (/includes/Smarty) is using a deprecated modifier β€˜e’ for preg_replace function call:

Block causing error: /include/Smarty/Smarty_Compiler.class.php @ line 262

/* replace special blocks by "{php}" */
        $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);

if you try simply to upgrade Smarty to the current version 3.1.16, or the closest available version 2.6.28. it will not work.

So I applied substitute call recommanded by PHP reference.
Change: /include/Smarty/Smarty_Compiler.class.php @ line 262

/* replace special blocks by "{php}" */
$source_content = preg_replace_callback($search, 
                function($m) { 
                    return "{php ".str_repeat("\n", substr_count($m[0], "\n"))."}";
                },
                  $source_content);      

I hope this will help someone else and save him few hours.

Actually this one works better:

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

Actually… this may be better :slight_smile:

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