praotes Posted July 15, 2013 Share Posted July 15, 2013 Dear Colleagues: We have upgraded our server to php5.5 and experience the following, as we run the Smarty template: 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 Quote Link to comment https://forums.phpfreaks.com/topic/280171-php55-preg_replace-the-e-modifier-is-deprecated-use-preg_replace_callback/ Share on other sites More sharing options...
requinix Posted July 15, 2013 Share Posted July 15, 2013 Upgrading to 5.5? Jumping the gun a bit much? preg_replace('/expr/e', 'foo', $string)is basically equivalent to preg_replace_callback('/expr/', function($matches) { return foo; }, $string)where foo is actual PHP code. You also have to deal with closures and scope, though, so your code ends up looking something like $self = $this; $source_content = preg_replace_callback($search, function($matches) use ($self) { return $self->_quote_replace($self->left_delimiter) . "php" . str_repeat("\n", substr_count($matches[0], "\n") . $self->_quote_replace($self->right_delimiter) }, $source_content); Quote Link to comment https://forums.phpfreaks.com/topic/280171-php55-preg_replace-the-e-modifier-is-deprecated-use-preg_replace_callback/#findComment-1440809 Share on other sites More sharing options...
praotes Posted July 16, 2013 Author Share Posted July 16, 2013 Dear Requinix: Apologies for the late reply. I was called away yesterday. Thanks for this coaching. We're merely working towards the future. PHP5.5 is supposed to be "stable" and PCI compliance seems to demand it. Thanks again, Hans Quote Link to comment https://forums.phpfreaks.com/topic/280171-php55-preg_replace-the-e-modifier-is-deprecated-use-preg_replace_callback/#findComment-1440925 Share on other sites More sharing options...
requinix Posted July 16, 2013 Share Posted July 16, 2013 PHP5.5 is supposed to be "stable" and PCI compliance seems to demand it."Supposed". That's the point. I applaud you moving to 5.5, don't get me wrong there. I just find it surprising someone would move to a .0 release of PHP that's not even a month old. PCI compliance probably wants you to be up to date with security patches. There's no way it could/should require you to be on the latest and greatest version of a product. Quote Link to comment https://forums.phpfreaks.com/topic/280171-php55-preg_replace-the-e-modifier-is-deprecated-use-preg_replace_callback/#findComment-1440941 Share on other sites More sharing options...
r3wt Posted November 6, 2013 Share Posted November 6, 2013 (edited) "Supposed". That's the point. I applaud you moving to 5.5, don't get me wrong there. I just find it surprising someone would move to a .0 release of PHP that's not even a month old. PCI compliance probably wants you to be up to date with security patches. There's no way it could/should require you to be on the latest and greatest version of a product. you can convey a point to someone more effectively by being a bit more down to earth. also i'm on php 5.5 as well, and still using preg with no problems. oddly enough, my ajax scripts seem to break with every upgrade, and the move to 5.5 was no exception. Edited November 6, 2013 by r3wt Quote Link to comment https://forums.phpfreaks.com/topic/280171-php55-preg_replace-the-e-modifier-is-deprecated-use-preg_replace_callback/#findComment-1457138 Share on other sites More sharing options...
trq Posted November 6, 2013 Share Posted November 6, 2013 That's the point. I applaud you moving to 5.5, don't get me wrong there. I just find it surprising someone would move to a .0 release of PHP that's not even a month old. 5.5.0 was released in June, 5.5 is certainly stable and is currently at 5.5.5 Quote Link to comment https://forums.phpfreaks.com/topic/280171-php55-preg_replace-the-e-modifier-is-deprecated-use-preg_replace_callback/#findComment-1457170 Share on other sites More sharing options...
mac_gyver Posted November 6, 2013 Share Posted November 6, 2013 @r3wt, you do realize this thread is months old and statements made back in july about a newly released major version of software no longer apply? Quote Link to comment https://forums.phpfreaks.com/topic/280171-php55-preg_replace-the-e-modifier-is-deprecated-use-preg_replace_callback/#findComment-1457201 Share on other sites More sharing options...
r3wt Posted November 8, 2013 Share Posted November 8, 2013 mac_gyver, i assumed he was talking about the minor subversion(5. 5.5). i didn't notice the thread was months old and he was referring to 5. 5.0 i do apologize for bumping this thread. Quote Link to comment https://forums.phpfreaks.com/topic/280171-php55-preg_replace-the-e-modifier-is-deprecated-use-preg_replace_callback/#findComment-1457511 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.