Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
php5.5 deprecated preg_replace.

 
Post new topic   Reply to topic    Smarty Forum Index -> Installation and Setup
View previous topic :: View next topic  
Author Message
praotes
Smarty n00b


Joined: 15 Jul 2013
Posts: 3

PostPosted: Mon Jul 15, 2013 1:31 am    Post subject: php5.5 deprecated preg_replace. Reply with quote

Dear Smarty Colleagues:

We have upgraded our server to php5.5 and experience the following:

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in xxx/xxxx/php5/smarty/base/Smarty_Compiler.class.php on line 270

The code as it currently is reads this...

/* 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);

QUESTION: Can you please explain what I need to change. The code directly below is identical to the one above, EXCEPT I replaced preg_replace with preg_replace_callback. The php5.5 instructions say I need to replace the "replacement" param with specifying a "callback." I know too little of php to do this, nor do I find a clear cut "replacement" param in this code.

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

Hope you can assist. Thanks!

Hans
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4592
Location: Hamburg / Germany

PostPosted: Mon Jul 15, 2013 6:36 pm    Post subject: Reply with quote

The /e modifier is just deprecated in php 5.5.

If you exclude E_DEPRECATED from error reporting the old code should still work.
Back to top
View user's profile Send private message
praotes
Smarty n00b


Joined: 15 Jul 2013
Posts: 3

PostPosted: Tue Jul 16, 2013 3:01 pm    Post subject: Disabling e_deprecated Reply with quote

Dear U-Tews:

I can follow that logic, and it is good to hear, but we rather only exclude STRICT error reporting, and like to see everything else so we can act on errors in a forward compatibility sort of way.

Would you be able to recommend how we adjust the Smarty 2.x code line? We have no option to upgrade to 3.x as it requires too many corrections all across our large application.

Hope you can assist. awaiting your thoughts, with warm regards,

Hans
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4592
Location: Hamburg / Germany

PostPosted: Tue Jul 16, 2013 7:49 pm    Post subject: Reply with quote

Here is the fix

Code:
        $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);


It'S also in the SVN at
https://smarty-php.googlecode.com/svn/branches/Smarty2Dev
Back to top
View user's profile Send private message
praotes
Smarty n00b


Joined: 15 Jul 2013
Posts: 3

PostPosted: Tue Jul 16, 2013 9:14 pm    Post subject: Superb... Reply with quote

Thanks so very much!! Very much appreciated.

Have a great day in Hamburg Smile

Greetings from BC, Canada,

Hans
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Installation and Setup All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP